improved permutation, still buggy.