fixed bug in permutation method, fixed tests