Fixed some logic in build_name_tree to, you know, work.