Bit of refactoring and basic autorotation support