Changes to the distance computation to make it faster