         editAction.backgroundColor = UIColor.info
         
         let favoriteAction = UITableViewRowAction(style: .normal, title: "Favorite", handler: { [unowned self] _, path in
-            let classAtPath = self.classObj(at: path)
-            let realm = try! Realm()
-            try! realm.write {
-                classAtPath.isFavorite = !classAtPath.isFavorite
-            }
+            self.updateFavoriteState(at: path)
             self.tableView.setEditing(false, animated: true)
-            self.tableView.reloadData()
         })
         
         favoriteAction.backgroundColor = UIColor.favorite

        if isSearchActive {
            return 0
        } else {
            if favoritedClasses.count > 0 && section == 0 {
                return 44
            } else if favoritedClasses.count > 0 && section != 0 {
                return classesBySection[section - 1].count > 0 ? 44 : 0
            } else {
                return classesBySection[section].count > 0 ? 44 : 0
            }
        }
    }

        if isSearchActive {
            return 1
        } else {
            // Add a section since favorited classes
            return classesBySection.count + 1
        }
    }

