use one file for recording/restoring, refactor