Make Undo more flexible