Add small checks for ranges (can happen if array unsorted)