refactoring of state machine, moving to c++11