more readable (and possibly more correct) tag tree building