Put the image download code in a function.