implemented distance functions