Preliminary implementation of distance function.