Construct state machine.