fix issue in restoreState() and saveState()