     if pa != pb
       return -1 if pa < pb
       return 1 if pa > pb
-      return 0
     # sort by descending profits
     return -1 if ca > cb
     return 1 if ca < cb
     return 0
 
+  # Index used for sorting
+  #
   profitability_index: (x) ->
     switch x.profitable
       when 'profitable' then 0
       when 'conditionally_profitable' then 1
       when 'unprofitable' then 2
 
+  # This hash maps dispatchable keys to the chart series labels used by the
+  # other merit order table
+  #
   series_labels:
     energy_chp_combined_cycle_network_gas: 'central_gas_chp'
     energy_chp_ultra_supercritical_coal: 'coal_chp'

    energy_power_ultra_supercritical_coal: 'coal_pwd'
    energy_power_ultra_supercritical_crude_oil: 'oil_plant'
    energy_power_ultra_supercritical_network_gas: 'gas_conv'

        profits_per_unit: values.profits_per_unit
        label: @series_labels[key] || key

    sorted_items = items.sort(@sorting_function)
    $('#merit-order-table').html tmpl({series: sorted_items})
    true

  # Sort by two fields
  #
  sorting_function: (a,b) =>
    pa = @profitability_index a
    pb = @profitability_index b
