distance function fix?