Fix the bug for undo method.