updated with range binary search