Did a first pass in refactoring the download logic. Another to come.