state machines

https://gist.github.com/mjallday/ee40a41595f34be1936e

Depends on #54.