Added robust state machine framework (needs work on checking transitions)