Index: trunk/FACT++/src/StateMachineDim.cc
===================================================================
--- trunk/FACT++/src/StateMachineDim.cc	(revision 14557)
+++ trunk/FACT++/src/StateMachineDim.cc	(revision 14558)
@@ -96,5 +96,5 @@
 //! Overwrite StateMachineImp::AddStateName. In addition to storing the
 //! state locally it is also propagated through Dim in the STATE_LIST
-//! service.
+//! service. 
 //!
 //! @param state
@@ -107,15 +107,20 @@
 //!    A explanatory text describing the state
 //!
-void StateMachineDim::AddStateName(const int state, const std::string &name, const std::string &doc)
-{
+bool StateMachineDim::AddStateName(const int state, const std::string &name, const std::string &doc)
+{
+    if (name.empty())
+        return false;
+
+    const bool rc = HasState(state) || GetStateIndex(name)!=kSM_NotAvailable;
+
     StateMachineImp::AddStateName(state, name, doc);
 
-    const string str0 = fDescriptionStates.itsData ? reinterpret_cast<char*>(fDescriptionStates.itsData) : "";
-    const string str1 = to_string(state)+':'+name+'=';
-
-    if (str0.find(str1)!=string::npos)
-        return;
-
-    fDescriptionStates.Update(str0+str1+doc+'\n');
+    string str;
+    for (auto it=fStateNames.begin(); it!=fStateNames.end(); it++)
+        str += to_string(state)+':'+name+'='+doc+'\n';
+
+    fDescriptionStates.Update(str);
+
+    return rc;
 }
 
Index: trunk/FACT++/src/StateMachineDim.h
===================================================================
--- trunk/FACT++/src/StateMachineDim.h	(revision 14557)
+++ trunk/FACT++/src/StateMachineDim.h	(revision 14558)
@@ -87,5 +87,5 @@
     int Write(const Time &time, const std::string &txt, int qos=kMessage);
 
-    void AddStateName(const int state, const std::string &name, const std::string &doc="");
+    bool AddStateName(const int state, const std::string &name, const std::string &doc="");
 };
 
Index: trunk/FACT++/src/StateMachineImp.cc
===================================================================
--- trunk/FACT++/src/StateMachineImp.cc	(revision 14557)
+++ trunk/FACT++/src/StateMachineImp.cc	(revision 14558)
@@ -659,8 +659,32 @@
 //!    A explanatory text describing the state
 //!
-void StateMachineImp::AddStateName(const int state, const std::string &name, const std::string &doc)
-{
-    if (fStateNames[state].first.empty())
-        fStateNames[state] = make_pair(name, doc);
+bool StateMachineImp::AddStateName(const int state, const std::string &name, const std::string &doc)
+{
+    //auto it = fStateNames.find(state);
+
+    //if (/*it!=fStateNames.end() &&*/ !it->second.first.empty())
+    //    return false;
+
+    fStateNames[state] = make_pair(name, doc);
+    return true;
+}
+
+// --------------------------------------------------------------------------
+//
+//! Get a state's index by its name.
+//!
+//! @param name
+//!    Name of the state to search for
+//!
+//! @returns
+//!    Index of the state if found, kSM_NotAvailable otherwise
+//!
+int StateMachineImp::GetStateIndex(const string &name) const
+{
+    for (auto it=fStateNames.begin(); it!=fStateNames.end(); it++)
+        if (it->second.first==name)
+            return it->first;
+
+    return kSM_NotAvailable;
 }
 
@@ -682,4 +706,17 @@
     s << state;
     return i==fStateNames.end() || i->second.first.empty() ? s.str() : i->second.first;
+}
+
+// --------------------------------------------------------------------------
+//
+//! @param state
+//!    The state for which should be checked
+//!
+//! @returns
+//!    true if a nam for this state already exists, false otherwise
+//!
+bool StateMachineImp::HasState(int state) const
+{
+    return fStateNames.find(state) != fStateNames.end();
 }
 
Index: trunk/FACT++/src/StateMachineImp.h
===================================================================
--- trunk/FACT++/src/StateMachineImp.h	(revision 14557)
+++ trunk/FACT++/src/StateMachineImp.h	(revision 14558)
@@ -22,9 +22,10 @@
     {
         kSM_KeepState    =    -42,  ///< 
-        kSM_NotReady   =     -1,  ///< Mainloop not running, state machine stopped
-        kSM_Ready      =      0,  ///< Mainloop running, state machine in operation
-        kSM_UserMode   =      1,  ///< First user defined mode (to be used in derived classes' enums)
-        kSM_Error      =  0x100,  ///< Error states should be between 0x100 and 0xffff
-        kSM_FatalError = 0xffff,  ///< Fatal error: stop program
+        kSM_NotAvailable =     -2,  ///< Possible return value for GetStateIndex
+        kSM_NotReady     =     -1,  ///< Mainloop not running, state machine stopped
+        kSM_Ready        =      0,  ///< Mainloop running, state machine in operation
+        kSM_UserMode     =      1,  ///< First user defined mode (to be used in derived classes' enums)
+        kSM_Error        =  0x100,  ///< Error states should be between 0x100 and 0xffff
+        kSM_FatalError   = 0xffff,  ///< Fatal error: stop program
     };
 
@@ -36,7 +37,9 @@
     typedef std::map<const int, std::pair<std::string, std::string>> StateNames;
 
+protected:
     /// Human readable names associated with the states
     StateNames fStateNames;
 
+private:
     std::vector<EventImp*> fListOfEvents; /// List of available commands as setup by user
     std::queue<Event*>     fEventQueue;   /// Event queue (fifo) for the received commands
@@ -87,5 +90,5 @@
     EventImp &AddEvent(const std::string &name, const std::string &fmt, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
 
-    virtual void AddStateName(const int state, const std::string &name, const std::string &doc="");
+    virtual bool AddStateName(const int state, const std::string &name, const std::string &doc="");
 
     void SetDefaultStateNames();
@@ -148,4 +151,7 @@
     void PrintListOfStates() const;
 
+
+    int GetStateIndex(const std::string &name) const;
+    bool HasState(int index) const;
 
     const std::string GetStateName(int state) const;
