Added orientation detection