Temporarely changed the distance funciton