Fixed euclidean distance not to create squared distance function on every call.