Modified rotation calculation to use modulo 360 degrees