Fixes distance calculation