Allow kwargs to be passed to build_*_tree, and fixed minor bugs in build_reference_tree