Autosave: refactored to be cleaner