Is there an easier way to do all of this?

AWOL:
And when you get bored of debugging that, use a multiplication instead of a division

:blush: