function downloadFile() - added

Revised the code for download a file. Used a function instead.