Sort properly in the presence of NaN