Improve performance of binary search