Completed saving and restore functions.