added enable and disable undo at appropriate points