Better implementation of num_range.
Thanks to @wch