refactored saving to form