added save image, refined structure