Refactored to use class for saving in preparation of saving images