Autosave function and some validation