Refactoring login workflow