Creation of state machine