write the framework for save and restore