refactored login API code