Feature/77 optimize tree

Prefix match subtree optimizations.

/cc @Hamcha @kyleterry