Building a dynamic match tree