               portIdentifier = "#{outport}[#{idx}]"
               unforwarded = @getForwardableContexts inport, portIdentifier, context
               continue unless unforwarded.length
+              forwardedOpens = []
               for ctx in unforwarded
+                debugBrackets "#{@nodeId} openBracket from '#{inport}' to '#{portIdentifier}': '#{ctx.ip.data}'"
                 ipClone = ctx.ip.clone()
                 ipClone.index = parseInt idx
-                idxIps.unshift ipClone
-                debugBrackets "#{@nodeId} openBracket from '#{inport}' to '#{portIdentifier}': '#{ctx.ip.data}'"
+                forwardedOpens.push ipClone
                 ctx.ports.push portIdentifier
+                @getBracketContext('out', outport, ctx.ip.scope, idx).push ctx
+              forwardedOpens.reverse()
+              idxIps.unshift ip for ip in forwardedOpens
             continue
           # Don't register ports we're only sending brackets to
           datas = ips.filter (ip) -> ip.type is 'data'
           continue unless datas.length
           unforwarded = @getForwardableContexts inport, outport, context
           continue unless unforwarded.length
+          forwardedOpens = []
           for ctx in unforwarded
-            ips.unshift ctx.ip.clone()
             debugBrackets "#{@nodeId} openBracket from '#{inport}' to '#{outport}': '#{ctx.ip.data}'"
+            forwardedOpens.push ctx.ip.clone()
             ctx.ports.push outport
+            @getBracketContext('out', outport, ctx.ip.scope).push ctx
+          forwardedOpens.reverse()
+          ips.unshift ip for ip in forwardedOpens
 
     if result.__bracketClosingAfter?.length
       for context in result.__bracketClosingAfter

    return

  getBracketContext: (type, port, scope, idx) ->
    portname = port
    if @inPorts[port].isAddressable()
      portname = "#{port}[#{idx}]"
    # Ensure we have a bracket context for the current scope
    @bracketContext[type][portname] = {} unless @bracketContext[type][portname]
    @bracketContext[type][portname][scope] = [] unless @bracketContext[type][portname][scope]
    return @bracketContext[type][portname][scope]

  addToResult: (result, port, ip, before = false) ->
    {name, index} = ports.normalizePortName port

        for port in context.ports
          ipClone = context.closeIp.clone()
          @addToResult result, port, ipClone, false
          @getBracketContext('out', port, ipClone.scope, ipClone.index).pop()

    delete result.__bracketClosingBefore
    delete result.__bracketContext
