sqrt added to distance function