Cleaned up implementation of autorotation