Fix distance bugs