Permutations for cluster analysis (unfinished). Some refactoring