Optimize the file download function