Moved download to a function.