added orientation detection