lift distance function out of main