Add Unit Tests.
Add function to run state machine.