fixed bug in rotation save-state; cleaned up code