Relocated the distance finder function