Refactor the fsm implementation and add tests