added distance function