better state machine construction and API