Fix sorting function, make use of generic array sort() function.