adding a working autosave function