Implemented distance functions.