Refactor the downloader, separate some functions