final working BST version