updated euclidean distance logic