refactoring on authentication process