changed to binary search