corrected the previously buggy implementation that could give incorrect results for some PERMS.