added permutation and updated atoms to eliminate unnecessary variable creation