Continued implementation of FSM.
Added UTs.