Switched to XYZ distance function