Refactoring login flow