Modified so that the download function follows redirects