Refactoring: Extracting expandUrl function