use qsort_r for sorting. Not portable - yet