Refactored login