Permission tests & refactoring