fix hierarchical state bug and add more test cases