Finite State machine Example Code