added check to treebuilder that parent is not null