Added build_tree(layers, first_node) function and test code