Fix for missing qsort_r()
Rearranged #if blocks