Added detection for losslessly rotated images
Minor cleanups