Fixed undo functionality bug