More on permissions. Some refactoring.