Working on state machine