improve and restructure fsm_client