Fixed treelist sorting using a custom qsort_r implementation.