Modified saving function