fixed bug in binary search