Fixes to distance.py