diff --git a/rocolib/api/ports/EdgePort.py b/rocolib/api/ports/EdgePort.py
index 60c2c44a198b47b23ee1cc78fc1ebb33a8a5e0cd..03a68558c19da40396fccfd6a8cc1911e8456dae 100644
--- a/rocolib/api/ports/EdgePort.py
+++ b/rocolib/api/ports/EdgePort.py
@@ -37,18 +37,21 @@ class EdgePort(Port):
     if isinstance(toPort, EdgePort):
       label1 = self.getEdges()
       label2 = toPort.getEdges()
+
+      numedges = len(label1)
+
       # XXX associate ports with specific composables so this isn't necessary
-      for i in range(len(label1)):
+      for i in range(numedges):
         if label1[i] not in (e.name for e in graph.edges):
           return
         if label2[i] not in (e.name for e in graph.edges):
           return
 
-      for i in range(len(label1)):
+      for i in range(numedges):
         newargs = {}
         for key, value in kwargs.items():
           if isinstance(value, (list, tuple)):
             newargs[key] = value[i]
           else:
             newargs[key] = value
-        graph.mergeEdge(label1[i], label2[i], **newargs)
+        graph.mergeEdge(label1[i], label2[numedges-i-1], **newargs)
diff --git a/rocolib/builders/ESPSegBuilder.py b/rocolib/builders/ESPSegBuilder.py
index d545bef8544067cdcc75cb3337f9d22cdca968ae..6ba94f413edce0ccc1fa15ff866b8d29d45f7559 100644
--- a/rocolib/builders/ESPSegBuilder.py
+++ b/rocolib/builders/ESPSegBuilder.py
@@ -43,10 +43,10 @@ c.addConstConstraint(("right","flip"), True)
 
 # connections
 c.addConnection(("brain", "topedge0"),
-                ("right", "botedge0"),
+                ("right", "topedge0"),
                 angle=-90)
 c.addConnection(("brain", "botedge0"),
-                ("left", "topedge0"),
+                ("left", "botedge0"),
                 angle=-90)
 
 # Sheath
@@ -65,7 +65,7 @@ c.addConstraint(("sheathsplit","botlength"), ("driveservo", "width"),
           x[1] - 2*getDim(x[0],'motorheight'), \
           getDim(x[0],'motorheight'))")
 
-c.addConnection(("left", "botedge1"),
+c.addConnection(("left", "topedge1"),
                 ("sheathsplit", "botedge2"),
                 angle=180)
 
@@ -76,7 +76,7 @@ c.addConnection(("right", "botedge1"),
 '''
 
 c.addConnection(("sheathsplit", "topedge0"),
-                ("sheath", "topedge1"))
+                ("sheath", "botedge1"))
 
 # Tail
 c.addSubcomponent("tail", "Tail", inherit=("flapwidth", "tailwidth"), prefix=None)
@@ -85,14 +85,14 @@ c.addConstraint(("tail","height"), *depthfn(["height"], "%s/2.+x[2]"))
 c.addConstraint(("tail","depth"), *depthfn(["battery"], "%s+x[2]"))
 
 c.addConnection(("tail", "topedge"),
-                ("sheath", "botedge1"),
+                ("sheath", "topedge1"),
                 angle=90)
 
 c.addSubcomponent("tailsplit", "SplitEdge")
 c.addConstraint(("tailsplit","toplength"), "width", "(x,)")
 c.addConstraint(("tailsplit","botlength"), ("width", "flapwidth"), "(x[0]*(1-x[1])/2., x[0]*x[1], x[0]*(1-x[1])/2.)")
 
-c.addConnection(("sheath", "botedge3"),
+c.addConnection(("sheath", "topedge3"),
                 ("tailsplit", "topedge0"))
 
 c.addConnection(("tail", "flapedge"),
diff --git a/rocolib/library/ESPSeg.yaml b/rocolib/library/ESPSeg.yaml
index 0c84eb9d1b85634930a8f32bb69daa7ec70dfc30..77254a21aa4fd5f5f3c46944144e1a5739afc904 100644
--- a/rocolib/library/ESPSeg.yaml
+++ b/rocolib/library/ESPSeg.yaml
@@ -3,17 +3,17 @@ connections:
   - - brain
     - topedge0
   - - right
-    - botedge0
+    - topedge0
   - angle: -90
   connection1:
   - - brain
     - botedge0
   - - left
-    - topedge0
+    - botedge0
   - angle: -90
   connection2:
   - - left
-    - botedge1
+    - topedge1
   - - sheathsplit
     - botedge2
   - angle: 180
@@ -21,17 +21,17 @@ connections:
   - - sheathsplit
     - topedge0
   - - sheath
-    - topedge1
+    - botedge1
   - {}
   connection4:
   - - tail
     - topedge
   - - sheath
-    - botedge1
+    - topedge1
   - angle: 90
   connection5:
   - - sheath
-    - botedge3
+    - topedge3
   - - tailsplit
     - topedge0
   - {}
diff --git a/rocolib/library/SimpleRectBeam.py b/rocolib/library/SimpleRectBeam.py
index 841762a26155c9f83ffb9d447bcb85568f30bf42..46b14c2fc6c8f48740a65edda7e4ceb5f6adcb63 100644
--- a/rocolib/library/SimpleRectBeam.py
+++ b/rocolib/library/SimpleRectBeam.py
@@ -10,8 +10,8 @@ class SimpleRectBeam(FoldedComponent):
     self.addParameter("addTabs", True, valueType="bool")
 
     for i in range(4):
-      self.addEdgeInterface("topedge%d" % i, "r%d.e0" % i, ["width", "depth"][i % 2])
-      self.addEdgeInterface("botedge%d" % i, "r%d.e2" % i, ["width", "depth"][i % 2])
+      self.addEdgeInterface("topedge%d" % i, "r%d.e2" % i, ["width", "depth"][i % 2])
+      self.addEdgeInterface("botedge%d" % i, "r%d.e0" % i, ["width", "depth"][i % 2])
       self.addFaceInterface("face%d" % i, "r%d" % i)
     self.addEdgeInterface("slotedge", "r3.e1", "length")
     self.addEdgeInterface("tabedge", "r0.e3", "length")