Fix problem with some images not being saved due to filename issues