refactoring authentication