Device rotation code refactored