modified function to download file