finalized BST code