revised isCanUndo function