Fixed bug in binary search