fixed bug with NaNs in distance matrix