corrected errors to download function