restructure FSM