refact code in unique bst