change fsm thread shutdown mechanism to make it more reliable