do not download files twice and better handle errors