replace Euclidean distance calcualation by vector subtraction and norm to speed up