implemented distance function, working

-tested on profile, but removed it.