Added an extra check on the images. To prevent corrupt data