Fix distance bug