Added distance function.