implement BST building