correct implementation of binary search tree check