handling NaN for Euclidean distance