still working on correct PERM algorithm