Added new code to demonstrate state machine