Fixed a bug with the orientation calculation.