State machine framework