modify distance function to diff