refactored login flow