demonstrate main state machine idiom