speed up distance calculation