Modified binarySearch