Refactored the rotation method. Added comments.