Extracted image downloading to a function.