added check to see if image exists before saving