Added state machine sample code