some progress on distance calculation