edit perm matrix function