Added function to calculate all distances