Login refactoring