encapsulate state machine creation