Dreamed up weird distance calculation code