diff --git a/src/js/ibcJS.js b/src/js/ibcJS.js
index 95129e4b9c0de365a85edd8a3b61effd23334238..b34126251aa47acca8d6d5024bbcf8f5afc9b886 100644
--- a/src/js/ibcJS.js
+++ b/src/js/ibcJS.js
@@ -1,7 +1,7 @@
-window.ibc = (() => {
+globalThis.ibc = (() => {
     // These IDs are considered to be unknown parents
     let or_null = (s) => specificCharacterID(s) ? s : null;
-    let find_gp = (id) => (slaveStateById(id) || genePool.find((s) => s.ID == id) || null);
+    let find_gp = (id) => (SugarCube.State.variables.genePool.find((s) => s.ID == id) || slaveStateById(id) || null);
 
     // Create a node for the given ID
     let create_node = (id) => ({
@@ -253,7 +253,8 @@ window.ibc = (() => {
             nodes[s.ID].father = (f === null) ? f : nodes[f];
 
             let sg = find_gp(s.ID);
-            if ("inbreedingCoeff" in sg && sg.inbreedingCoeff !== -1) {
+            if (sg !== null && "inbreedingCoeff" in sg && sg.inbreedingCoeff !== -1) {
+                console.log("Found "+s.ID);
                 nodes[s.ID]._coeff = sg.inbreedingCoeff;
             }
         };
@@ -278,16 +279,6 @@ window.ibc = (() => {
             ret[s.ID] = coeff(nodes[s.ID]);
         });
 
-        Object.keys(nodes).forEach(s => {
-            let n = nodes[s];
-            if (n.id in SugarCube.State.variables.slaveIndices) {
-                let slave = find_gp(n.id);
-                if (!("inbreedingCoeff" in slave) || slave.inbreedingCoeff === -1) {
-                    slave.inbreedingCoeff = n._coeff;
-                }
-            }
-        });
-
         return ret;
     };