Add boundary checking for rotation.

I think this works. :O