Fixed bug in distance calculation.
Improved integration test.