Redesign the interface of distance function