combined att/def sort function