correcting euclidean distance formula (division by zero)