Added extra checks for image retrieval.