break out downloading into a separate func so defer works