fix binary search bugs