changed distance method to n-d