Fixed distance calculation

Fixes #90, probably broken in 8e981ec8e9586d5779143627ade0f155a22c8069