added check if undoManager exists (closes #8)