refactored login process