fixing permutation bug and Analysis script