next_range bug fix