Changed BinarySearch to pattern matching.