Add unit test for DictGroup::MatchAllPrefixes

Also refine some code