Added permuting and tests.