some refactoring of perm calculation