Extract http functionality to a separate file; refactor.