fixed memory problem when retrieving an image from the gallery, and a bug which returned the images rotated