const cache = {};
Flow({
    set: (key, val) => {
        return cache[key] = val;
    },
    get: (key) => {
        return cache[key];
    },
    del: (key) => {
        delete cache[key];
    },
    seq: (sequenceId, role) => {
        // TODO here we could load a sequence from the safenetwork
        return fetch("/.sq/" + sequenceId).then((response) => {

            if (!response.ok) {
                return Promise.reject(response.statusText);
            }

            return response.json();
        });
    },
    fnc: (fn_iri, role) => {
        // TODO here we could load the handler bundle form the safenetwork
        return new Promise((resolve, reject) => {
            const node = document.createElement("script");
            node.onload = () => {
                node.remove();
                resolve(fn_iri);
            };
            node.src = "/.fn/" + fn_iri;
            document.head.appendChild(node);
        });
    },
    dep: (name, dependency) => {
        return new Promise((resolve, reject) => {
            const node = document.createElement("script");
            node.onload = () => {
                node.remove();
                resolve(name);
            };
            node.src = "/.dp/" + dependency;
            document.head.appendChild(node);
        });
    }
});

@@ -11,16 +11,323 @@
 e = %7B%7D;%0A
+function loadScript (name, src) %7B%0A    return new Promise((resolve, reject) =%3E %7B%0A        const node = document.createElement(%22script%22);%0A        node.onload = () =%3E %7B%0A            node.remove();%0A            resolve(result);%0A        %7D;%0A        node.src = src;%0A        document.head.appendChild(node);%0A    %7D);%0A%7D%0A
 Flow(%7B%0A 
@@ -662,17 +662,16 @@
 e) =%3E %7B%0A
-%0A
         
@@ -678,13 +678,15 @@
     
-if (!
+return 
 resp
@@ -696,34 +696,28 @@
 e.ok
-) %7B%0A                return
+ ? response.json() :
  Pro
@@ -754,59 +754,8 @@
 t);%0A
-            %7D%0A%0A            return response.json();%0A
     
@@ -849,14 +849,14 @@
 ler 
-bundle
+script
  for
@@ -885,679 +885,131 @@
     
-return new Promise((resolve, reject) =%3E %7B%0A            const node = document.createElement(%22script%22);%0A            node.onload = () =%3E %7B%0A                node.remove();%0A                resolve(fn_iri);%0A            %7D;%0A            node.src = %22/.fn/%22 + fn_iri;%0A            document.head.appendChild(node);%0A        %7D);%0A    %7D,%0A    dep: (name, dependency) =%3E %7B%0A        return new Promise((resolve, reject) =%3E %7B%0A            const node = document.createElement(%22script%22);%0A            node.onload = () =%3E %7B%0A                node.remove();%0A                resolve(name);%0A            %7D;%0A            node.src = %22/.dp/%22 + dependency;%0A            document.head.appendChild(node);%0A        %7D
+loadScript(fn_iri, %22/.fn/%22 + fn_iri);%0A    %7D,%0A    dep: (name, dependency) =%3E %7B%0A        loadScript(name, %22/.dp/%22 + dependency
 );%0A 

put redunant code in a function