Save function updated