rebuilding the BST function