Fixing permute functions.