Replace linear search with binary search