+# Wrappers for AMD and CommonJS. Fallback to global scope.
 ((root, factory) ->
 
+    # If AMD is used.
     if typeof define is "function" and define.amd
         define [], factory
+
+    # If CommonJS is used.
     else if typeof module is "object" and module.exports
         module.exports = factory()
+
+    # Otherwise bind to `window` object.
     else
         root.AriaTips = factory()
 
 )(this, ->
 
-    arrowDelta = 6
-
+    ###
+        * Tooltips are the elements that are displayed when the mouse hovers a
+        trigger.
+
+        * Triggers are the elements that listen to mouseover events in order to
+        show the tooltips.
+    ###
+
+
+    # Number of pixels the tooltip's arrow takes.
+    ARROW_DELTA = 6
+
+
+    # Unbinders are functions that unbind events on triggers. They are defined
+    # when the events are bound.
     unbinders = []
 
+
+    # Do all the magic needed to show the tooltips!
+    bindAll = ->
+        # Unbind all existing events in order to prevent listening to the same
+        # event multiple times.
+        unbindAll()
+
+        # Get all tooltips in the DOM.
+        tips = document.querySelectorAll '[role=tooltip]'
+
+        for tip in tips
+            # Tooltips need to be appended to body for global positioning.
+            document.body.appendChild tip
+
+            # Get all triggers in the DOM.
+            triggers = document.querySelectorAll "[aria-describedby=#{tip.id}]"
+            for trigger in triggers
+
+                # Bind the mouseover/mouseout events on the trigger.
+                unbinder = bindEvents.call trigger
+
+                # Store the returned function to unbind the events if needed.
+                unbinders.push unbinder
+
+
+    # Remove all the magic that show the tooltips.
+    unbindAll = ->
+        unbinder() for unbinder in unbinders
+        unbinders = []
+
+
+    # Return the opposite position, given a position.
     oppositePosition = (position) ->
         switch position
             when 'top'    then 'bottom'


        return unbindEvents

    return {
        bind: -> attachTooltips()
        unbind: -> unbindAll()
    }

)

                tip.setAttribute 'aria-hidden', true
            , 30


        # Bind the actual events.
        @addEventListener 'mouseover', onMouseOver
        @addEventListener 'mouseout', onMouseOut

        # Since a tooltip management is scoped (there is one pair of handlers
        # for onMouseOver/onMouseOut events for each trigger), we return an
        # unbind function so it can be called later on.
        unbindEvents = =>
            tip.removeEventListener 'mouseover', onMouseOver
            tip.removeEventListener 'mouseout', onMouseOut
