Elm.Native.Ports = {};
Elm.Native.Ports.make = function(elm) {
    elm.Native = elm.Native || {};
    elm.Native.Ports = elm.Native.Ports || {};
    if (elm.Native.Ports.values) return elm.Native.Ports.values;

    var Signal = Elm.Signal.make(elm);

    function incomingSignal(converter) {
        converter.isSignal = true;
        return converter;
    }

    function outgoingSignal(converter) {
        return function(signal) {
            var subscribers = []
            function subscribe(handler) {
                subscribers.push(handler);
            }
            function unsubscribe(handler) {
                subscribers.pop(subscribers.indexOf(handler));
            }
            A2( Signal.lift, function(value) {
                var val = converter(value);
                var len = subscribers.length;
                for (var i = 0; i < len; ++i) {
                    subscribers[i](val);
                }
            }, signal);
            return { subscribe:subscribe, unsubscribe:unsubscribe };
        }
    }

    function portIn(name, converter) {
        var jsValue = elm.ports.incoming[name];
        if (jsValue === undefined) {
            throw new Error("Initialization Error: port '" + name +
                            "' was not given an input!");
        }
        elm.ports.uses[name] += 1;
        try {
            var elmValue = converter(jsValue);
        } catch(e) {
            throw new Error("Initialization Error on port '" + name + "': \n" + e.message);
        }

        // just return a static value if it is not a signal
        if (!converter.isSignal) {
            return elmValue;
        }

        // create a signal if necessary
        var signal = Signal.constant(elmValue);
        function send(jsValue) {
            try {
                var elmValue = converter(jsValue);
            } catch(e) {
                throw new Error("Error sending to port '" + name + "': \n" + e.message);
            }
            setTimeout(function() {
                elm.notify(signal.id, elmValue);
            }, 0);
        }
        elm.ports.outgoing[name] = { send:send };
        return signal;
    }

    function portOut(name, converter, value) {
        try {
            elm.ports.outgoing[name] = converter(value);
        } catch(e) {
            throw new Error("Initialization Error on port '" + name + "': \n" + e.message);
        }
        return value;
    }

    return elm.Native.Ports.values = {
        incomingSignal: incomingSignal,
        outgoingSignal: outgoingSignal,
        portOut: portOut,
        portIn: portIn
    };
};

@@ -53,35 +53,62 @@
 ion(
-elm) %7B%0A    elm.Native = elm
+localRuntime) %7B%0A    localRuntime.Native = localRuntime
 .Nat
@@ -122,19 +122,28 @@
 %7B%7D;%0A    
-elm
+localRuntime
 .Native.
@@ -150,19 +150,28 @@
 Ports = 
-elm
+localRuntime
 .Native.
@@ -191,19 +191,28 @@
     if (
-elm
+localRuntime
 .Native.
@@ -225,26 +225,45 @@
 values) 
-return elm
+%7B%0A        return localRuntime
 .Native.
@@ -275,16 +275,22 @@
 .values;
+%0A    %7D
 %0A%0A    va
@@ -316,19 +316,28 @@
 al.make(
-elm
+localRuntime
 );%0A%0A    
@@ -1184,19 +1184,28 @@
 Value = 
-elm
+localRuntime
 .ports.i
@@ -1396,27 +1396,36 @@
   %7D%0A        
-elm
+localRuntime
 .ports.uses%5B
@@ -2126,19 +2126,28 @@
         
-elm
+localRuntime
 .notify(
@@ -2197,35 +2197,44 @@
       %7D%0A        
-elm
+localRuntime
 .ports.outgoing%5B
@@ -2359,19 +2359,28 @@
         
-elm
+localRuntime
 .ports.o
@@ -2576,19 +2576,28 @@
  return 
-elm
+localRuntime
 .Native.
@@ -2752,8 +2752,9 @@
   %7D;%0A%7D;%0A
+%0A

rename elm to localRuntime