AI rotation bug fixed

And a little code cleanup