code for  distance measures