Added and improved function to save created image