working state machine and a few unit tests