Add Comments and change the distance function