Added code to check image orientation and fix