rewrite vector_distance function