use a better sort function