rewrite record_undo