This code is what I actually have, and I need to rewrite it to use an easier way.
Sounds like an assignment or homework.