Initial commit of the state machine implementation, including tests.