--move distance functions into separate library