Revised: add code to save images.