Simple state machine and example usage