improved FSM