Changed distance function to probabilistic method
Made changes for Dan
Fixed merge conflicts with Dan