Fixes the distance function, and other test fixes. Now, works as needed.