Modified logic to download file with correct extension.