   #makeTooltip: $el, $target -> $tooltip
   #removeTooltip: $el, $target, $tooltip ->
 
-ttCounter = 0
+ttCounter = 0 #each call to TooltipJQ gets its own id based on this.
 
 #returns an object with a close method which when called
 #removes all open tooltips
 Backbone.Factlink.TooltipJQ = (options) ->
   uid = ttCounter++
   uidStr = 'tooltipUid-' + uid
-  instCounter = 0
+  instCounter = 0 #one call can cause multiple tooltips
+  #we track each tooltip using the instCounter and store them
+  #in `instances`: this means we can close them not just
+  #in reponse to an event handler, but also on request
   instances = {}
 
   $el = options.$el

  hoverTarget = (inTarget) -> (e) ->
    $target = $(e.currentTarget)
    ttActions = instances[$target.data(uidStr)]
    if ttActions
      ttActions.setTargetHover inTarget
    else if inTarget
      openInstance $target

  $el.hoverIntent

  openInstance = ($target) ->
    instId = 'tt' + instCounter++
    inTooltip = false
    inTarget = true #opened on hover over target

    $tooltip = options.makeTooltip $el, $target
    $tooltip.hoverIntent
