improve speed of function my.dist, not much unfortunately :(