fix distance calculation