modify the save and restoreToCount method