Clean up
Generalize rotate optimization