Complete rewrite of downloader script