Implemented distance between function