Fix bug in binary search