                 database.deleteEnclosure($0, callback: checkForCompleted)
             }
 
-            dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
+            lock.lock()
             finish()
         }
     }

                    }
                }

                dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
                finish()
            }
        }

            let enclosures = articles.reduce([Enclosure]()) { $0 + Array($1.enclosuresArray) }

            var totalRemaining = feeds.count + articles.count + enclosures.count
            let lock = NSRecursiveLock()

            let checkForCompleted = {
                totalRemaining -= 1
                if totalRemaining == 0 {
                    lock.unlock()
                }
            }

