Added undo logic.