configurable distance function
configurable distance