full undo implementation