Add state machine and some TDD