minor changes to distance.js

you should review this and test before merging as we did not test
locally