Added code to write out images and bag without images.