made distance computation generic