Cleaned orientation handling code