improved FSM according to what Paolo had in mind