updated the saving function