Authentication refactoring