move the rm commands to after the images are used