A C# hierarchical state machine