Refactor out comparator and descending logic into util methods.