Finish up distance function.