Rewrite download function.