Implementation and use of an Finite State Machines