That's some nice trig function work there at the beginning with the loops.