Completed sortByRange. TODO verification