         return URLSession(configuration: configuration, delegate: self, delegateQueue: OperationQueue())
     }
 
-    /// Maps download url to the task handling the download
-    private var downloadedUrls: [URL: URLSessionDownloadTask] = [:]
+    /// Maps task handling the download to the download task
+    private var downloadedUrls: [URLSessionDownloadTask: URL] = [:]
 
     func download(episode: EpisodeMO) {
         guard let appDelegate = UIApplication.shared.delegate as? AppDelegate,

        // Fetch download info by identifier
        if let downloadInfo = DownloadInfo.fetchDownloadInfo(with: task.taskIdentifier) {
            downloadInfo.setValue(DownloadInfoStatus.failed, forKey: DownloadInfo.Keys.status)
        }
        saveData()
        // Send notification about error
        // Do we need to send user info?
        NotificationCenter.default.post(name: .didFailDownload, object: nil)
    }

}

    }

    func cancel(episode: EpisodeMO) {
        guard let url = episode.audioURL else { return }
        let taskForURL = downloadedUrls.filter{ $0.value == url }.map{ $0.key }.first
        guard let task = taskForURL else { return }
        task.cancel(byProducingResumeData: { resumeData in
            // store resumeData in DownloadInfo
            if let data = resumeData,
