Fix handling of NaN and missing rows