refactored login functions