save/load code refactoring