sort order refactored