Changed the distance function I'm using