 
         // Clean-up.
         do {
-            try NSFileManager.defaultManager().removeItemAtPath(self.tmpDir!)
+            try NSFileManager.defaultManager().removeItemAtPath(tmpDir)
         } catch _ {
             // Ignore error
         }
-        self.tmpDir = nil
-        self.settingsFilePath = nil
-        self.objectsFilePaths = nil
+        tmpDir = nil
+        settingsFilePath = nil
+        objectsFilePaths = nil
+        buildIndexOperation = nil
         
         // Mark the sync as finished.
         self.syncing = false

    }
    
    // ----------------------------------------------------------------------
    // MARK: Search
    // ----------------------------------------------------------------------

    @objc public override func search(query: Query, completionHandler: CompletionHandler) -> NSOperation {

            }
            assert(self.syncError != nil) // we should reach this point only in case of error (see above)
        }
        offlineClient.buildQueue.addOperation(settingsOperation)
        
        // Task: build the index using the downloaded files.
        buildIndexOperation = NSBlockOperation() {
            if self.syncError == nil {
                let status = self.localIndex!.buildFromSettingsFile(self.settingsFilePath, objectFiles: self.objectsFilePaths, clearIndex: true)
                if status != 200 {
                    self.syncError = NSError(domain: Client.ErrorDomain, code: Int(status), userInfo: [NSLocalizedDescriptionKey: "Could not build local index"])
                } else {
