break out download into separate function