Sorting for range reporting

Sorting for range reporting and test improvements