Fixing several errors in generation of NxT distance matrix