rewrite the distance function in loessf