fixed function saveFinalImage