fsm solution