Fix UndoStack issues and decouple from CMDTYPE definition