Some refactoring to autosave