Updated Sorting Comparater to handle NaN