Starting complete rework of the state machine. Integration test compiles and mostly fails, as expected.