refactor downloading code to fix apple and yahoo-redir downloading