Move URL fetch code to its own function