     }
 
     public func isBookmarked(url: String) -> Deferred<Maybe<Bool>> {
-        var err: NSError?
-        let sql = "SELECT id FROM \(TableBookmarks) WHERE url = ? LIMIT 1"
-        let args: Args = [url]
-
-        let c = db.withReadableConnection(&err) { (conn, err) -> Cursor<Int> in
-            return conn.executeQuery(sql, factory: { $0["id"] as! Int }, withArgs: args)
-        }
-
-        if c.status == .Success {
-            return deferMaybe(c.count > 0)
-        }
-        return deferMaybe(DatabaseError(err: err))
-    }
-
+        let sql = "SELECT id FROM " +
+            "(SELECT id FROM \(TableBookmarksLocal) WHERE " +
+            " bmkUri = ? AND is_deleted IS NOT 1" +
+            " UNION ALL " +
+            " SELECT id FROM \(TableBookmarksMirror) WHERE " +
+            " bmkUri = ? AND is_deleted IS NOT 1 AND is_overridden IS NOT 1" +
+            " LIMIT 1)"
+        let args: Args = [url, url]
+
+        return self.db.runQuery(sql, args: args, factory: { $0["id"] as! Int })
+            >>== { cursor in
+                return deferMaybe((cursor.status == .Success) && (cursor.count > 0))
+        }
+    }
+
+    // TODO: rewrite me.
     public func clearBookmarks() -> Success {
         return self.db.run([
-            ("DELETE FROM \(TableBookmarks) WHERE parent IS NOT ?", [BookmarkRoots.RootID]),
+            ("DELETE FROM \(TableBookmarksLocal) WHERE parentid IS NOT ?", [BookmarkRoots.RootGUID]),
             self.favicons.getCleanupCommands()
         ])
     }
 
+    // TODO: rewrite me.
     public func removeByURL(url: String) -> Success {
         return self.db.run([
-            ("DELETE FROM \(TableBookmarks) WHERE url = ?", [url]),
+            ("DELETE FROM \(TableBookmarksLocal) WHERE bmkUri = ?", [url]),
         ])
     }
 
+    // TODO: rewrite me.
     public func remove(bookmark: BookmarkNode) -> Success {
         let sql: String
         let args: Args
         if let id = bookmark.id {
-            sql = "DELETE FROM \(TableBookmarks) WHERE id = ?"
+            sql = "DELETE FROM \(TableBookmarksLocal) WHERE id = ?"
             args = [id]
         } else {
-            sql = "DELETE FROM \(TableBookmarks) WHERE guid = ?"
+            sql = "DELETE FROM \(TableBookmarksLocal) WHERE guid = ?"
             args = [bookmark.guid]
         }
 


    public func modelForRoot() -> Deferred<Maybe<BookmarksModel>> {
        // Return a virtual model containing "Desktop bookmarks" prepended to the local mobile bookmarks.

        guard let mobile = self.local.folderForGUID(BookmarkRoots.MobileFolderGUID, title: BookmarksFolderTitleMobile) else {
            return deferMaybe(DatabaseError(description: "Unable to fetch mobile bookmarks."))
        }

        return self.mirror.extendWithDesktopBookmarksFolder(mobile, factory: self)
    }

    // Whenever async construction is necessary, we fall into a pattern of needing


extension SQLiteBookmarkMirrorStorage: BookmarksModelFactory {
    private func getDesktopRoots() -> Deferred<Maybe<Cursor<BookmarkNode>>> {
        // We deliberately exclude the mobile folder, because we're inverting the containment
        // relationship here.
        let args: Args = [BookmarkRoots.RootGUID, BookmarkRoots.MobileFolderGUID]
        let folderType = BookmarkNodeType.Folder.rawValue
        let sql =
        "SELECT id, guid, type, title FROM \(TableBookmarksMirror) WHERE " +
        "parentid = ? AND " +
        "is_deleted = 0 AND " +
        "type = \(folderType) AND " +
        "guid IS NOT ? AND " +
        "title IS NOT '' " +
        "ORDER BY guid ASC"
        return self.db.runQuery(sql, args: args, factory: BookmarkFactory.factory)
    }

    private func cursorForGUID(guid: GUID) -> Deferred<Maybe<Cursor<BookmarkNode>>> {
