check permissions refactoring