Modified code to restrict newRotation's value to within 360 with signs