Add error channel to catch exceptions thrown inside the state machine's go block. Detect non-existent states returned from state functions. Add tests.