             text:                order.number
             title:               utils.i18n 'order_title'
         ],
-        $('<td/>').append $ '<span/>', text: getStatusText i
+        $('<td/>').append $ '<span/>', text: getStatusText order
       ]
     )
     # Order had an error; I suppose I should tell the user.

  encode = encodeURIComponent
  return "#{ORDER_URL}#{encode order.number}/#{encode order.code}"

# Attempt to derive the status text to be displayed for the indexed order.  
# The status text will either be that of the latest update or a single
# whitespace character if no status updates have been detected yet for that
# order.
getStatusText = (index) ->
  length = ext.orders[index].updates.length
  return ' ' if length is 0
  return ext.orders[index].updates[length - 1].status

# Return the total number of detected status updates for all existing orders
# since the last time badges were cleared.

# If no existing tab exists a new one is simply created.
selectOrCreateTab = (url, callback) ->
  chrome.windows.getCurrent (win) ->
    chrome.tabs.query windowId: win.id, (tabs) ->
      # Try to find an existing tab.
      for tab in tabs
        if tab.url.indexOf(url) is 0
          existingTab = tab
          break
      if existingTab
        # Found one! Now to select it.
        chrome.tabs.update existingTab.id, selected: yes
        callback? no
      else
        # Ach well, let's just create a new one.
