Fixed return in distance function