 
 class SaveButtonsController: NSObject, SaveButtonDelegate {
     
+    // The tag refers to a specific article button, which takes the article database key and language variant into account
+    // But we need to keep all save buttons for an article, across all variants, updated with the same value
+    // visibleSaveButtonTagsByDatabaseKey maps from the database key - equal for all variants to a set of tags of all the buttons for that article
+    // visibleSaveButtons maps the tag to the save button.
     var visibleSaveButtons = [Int: Set<SaveButton>]()
+    var visibleSaveButtonTagsByDatabaseKey = [String: Set<Int>]()
     var visibleArticleKeys = [Int: WMFInMemoryURLKey]()
     var visibleUserInfo = [Int: Any]()
     

        saveButton.tag = tag
        saveButton.addTarget(self, action: #selector(saveButtonPressed(sender:)), for: .touchUpInside)
        saveButton.saveButtonDelegate = self
        var saveButtons = visibleSaveButtons[tag] ?? []
        saveButtons.insert(saveButton)
        visibleSaveButtons[tag] = saveButtons
        visibleArticleKeys[tag] = key
        visibleUserInfo[tag] = userInfo
    }
    
    public func didEndDisplaying(saveButton: SaveButton, for article: WMFArticle) {
        guard let key = article.inMemoryKey else {
            return
        }
        let tag = key.hash

            visibleUserInfo.removeValue(forKey: tag)
        } else {
            visibleSaveButtons[tag] = saveButtons
        }
        
        var saveButtonTags = visibleSaveButtonTagsByDatabaseKey[databaseKey] ?? []
        saveButtonTags.remove(tag)
        if saveButtonTags.isEmpty {
            visibleSaveButtonTagsByDatabaseKey.removeValue(forKey: databaseKey)
        } else {
            visibleSaveButtonTagsByDatabaseKey[databaseKey] = saveButtonTags
        }
    }
    
