Fixed bug where image is sometimes cropped