Added statemachine

This statemachine works of dictionary lookups and callbacks.
Added unit testing for statemachine

This is still missing some corner cases, but I plan to
use this in another project, so if I find bugs there
I will add unit tests here.