fixed all the permutation functions

Signed-off-by: McSherry <liamj.mcsherry@googlemail.com>