FIX: distance array now only transposed once