authentication refactoring