update the permuteMatrix method