Changed the way cpp distance functions are called