Fix memory map size.
Fix permutation handling on the distance computation.