fixed sorting (now handles missing values)