Optimized binary search