Added error checking to reading of image