added orientation detection, not tested