Add support for save and load state.