Adding NaN handling in profiles and histograms