Corrected a bug in undo method