Improved vector distance functions. More cleanups