fixed bug that causes too many images to be saved