fixed the permutation detection