Completed buildTree method in generate_tree.py