Fixed undo buffer functionality