Fleshed out distance functions.
Changed some function interfaces.