Changed orientation detection and fixed null pointer exception