Working version of BST