change to thread safe fsm