diff --git a/agui2/Graphics/Connection.cpp b/agui2/Graphics/Connection.cpp
index c343ce61581130cf99c99a5393e49bf336c314c1..6382a8dc41b1f88a0d89704dd154287938a45074 100644
--- a/agui2/Graphics/Connection.cpp
+++ b/agui2/Graphics/Connection.cpp
@@ -4,17 +4,23 @@
 #include <QPainter>
 
 #include <Graphics/ConnectionBox.h>
+#include <Graphics/GraphicsBox.h>
 #include <Utils.h>
 
 Connection::Connection(ConnectionBox* origin, ConnectionBox* target)
     : originConnectionBox(origin)
     , targetConnectionBox(target)
 {
+    Q_ASSERT(origin->getType() == ConnectionBox::Type::Output);
+    Q_ASSERT(target->getType() == ConnectionBox::Type::Input);
     this->setZValue(2);
     this->boundRect = Utils::pointsToRect(origin->pos(), target->pos());
     this->boundRect.adjust(-1, -1, 1, 1);
     origin->scene()->addItem(this);
     origin->scene()->update();
+
+    origin->getWrapperBox()->addOutput(target->getWrapperBox(), nullptr);
+    target->getWrapperBox()->addInput(origin->getWrapperBox(), nullptr);
 }
 
 QRectF Connection::boundingRect() const {
@@ -45,8 +51,3 @@ void Connection::recalculateBoundingRect(const QPointF& a, const QPointF& b) {
     this->boundRect = Utils::pointsToRect(a, b);
     this->boundRect.adjust(-1, -1, 1, 1);
 }
-
-void Connection::destroy() {
-    this->originConnectionBox->connection.reset();
-    this->targetConnectionBox->connection.reset();
-}
diff --git a/agui2/Graphics/Connection.h b/agui2/Graphics/Connection.h
index 89cf91ac3d3408349c3a60c30ef60d2389c3f194..0b10090a67ad70cc1beab367082014219137acfb 100644
--- a/agui2/Graphics/Connection.h
+++ b/agui2/Graphics/Connection.h
@@ -11,8 +11,9 @@ public:
     QRectF boundingRect() const override;
 
     void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
-
-    void destroy();
+    
+    ConnectionBox* getOriginConnectionBox() const { return this->originConnectionBox; }
+    ConnectionBox* getTargetConnectionBox() const { return this->targetConnectionBox; }
 
 private:
     void recalculateBoundingRect(const QPointF& topLeft, const QPointF& bottomRight);
diff --git a/agui2/Graphics/ConnectionBox.cpp b/agui2/Graphics/ConnectionBox.cpp
index bc9ffb6590e1bf3e168ed0f31154cdfb5b5e3fa7..ad016f9fc5c4a3971a67389806ca0e7c7406cfff 100644
--- a/agui2/Graphics/ConnectionBox.cpp
+++ b/agui2/Graphics/ConnectionBox.cpp
@@ -10,19 +10,15 @@
 
 const QColor ConnectionBox::defaultColor = Qt::white;
 
-ConnectionBox::ConnectionBox(GraphicsBox* parent, bool isInput)
+ConnectionBox::ConnectionBox(GraphicsBox* parent, Type type)
     : QGraphicsRectItem(-8, -8, 16, 16, parent)
-    , isInput(isInput)
+    , _type(type)
 
 {
     this->setBrush(ConnectionBox::defaultColor);
     this->setAcceptedMouseButtons(Qt::LeftButton);
 }
 
-GraphicsBox* ConnectionBox::getParent() const {
-    return dynamic_cast<GraphicsBox*>(this->parentObject());
-}
-
 void ConnectionBox::mousePressEvent(QGraphicsSceneMouseEvent* event) {
     this->setCursor(Qt::UpArrowCursor);
 
@@ -53,7 +49,7 @@ void ConnectionBox::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
         }
     }
 
-    if (other && other->isInput == !this->isInput)
+    if (other && other->getType() != this->getType())
     {
         other->setColor(Qt::yellow);
     }
@@ -67,7 +63,7 @@ void ConnectionBox::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
     this->tempLine = nullptr;
 
     auto* other = dynamic_cast<ConnectionBox*>(this->scene()->itemAt(event->scenePos(), {}));
-    if (other && other->isInput == !this->isInput)
+    if (other && other->getType() != this->getType())
     {
         this->setColor(ConnectionBox::defaultColor);
         other->setColor(ConnectionBox::defaultColor);
@@ -76,10 +72,10 @@ void ConnectionBox::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
 }
 
 void ConnectionBox::connect(ConnectionBox* a, ConnectionBox* b) {
-    Q_ASSERT(a->isInput != b->isInput);
+    Q_ASSERT(a->getType() != b->getType());
     auto* origin = a;
     auto* target = b;
-    if (origin->isInput)
+    if (origin->getType() == ConnectionBox::Type::Input)
         std::swap(origin, target);
 
     origin->connection = target->connection = std::make_shared<Connection>(origin, target);
@@ -94,7 +90,13 @@ void ConnectionBox::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) {
 }
 
 void ConnectionBox::on_Disconnect() {
-    this->connection->destroy();
+    auto* origin = this->connection->getOriginConnectionBox();
+    auto* target = this->connection->getTargetConnectionBox();
+    origin->getWrapperBox()->removeOutput();
+    target->getWrapperBox()->removeInput(origin->getWrapperBox(), nullptr);
+
+    origin->connection.reset();
+    target->connection.reset();
 }
 
 void ConnectionBox::setColor(QColor color) {
@@ -102,3 +104,7 @@ void ConnectionBox::setColor(QColor color) {
     brush.setColor(color);
     this->setBrush(brush);
 }
+
+WrapperBox* ConnectionBox::getWrapperBox() const {
+    return dynamic_cast<GraphicsBox*>(this->parentObject())->getWrapperBox();
+}
diff --git a/agui2/Graphics/ConnectionBox.h b/agui2/Graphics/ConnectionBox.h
index c4fafe4357d60d245906a99be7a1a3516384b2db..c560aae739c9b3068dc6a84afdf1e48a722d73c8 100644
--- a/agui2/Graphics/ConnectionBox.h
+++ b/agui2/Graphics/ConnectionBox.h
@@ -6,17 +6,25 @@
 #include <Graphics/Connection.h>
 
 class GraphicsBox;
+class WrapperBox;
 
 class ConnectionBox : public QObject, public QGraphicsRectItem {
     Q_OBJECT
 
-friend class Connection;
-
 public:
-    ConnectionBox(GraphicsBox* parent, bool isInput);
+    enum class Type
+    {
+        Input,
+        Output
+    };
+
+    ConnectionBox(GraphicsBox* parent, Type type);
 
     static const QColor defaultColor;
 
+    Type getType() const { return this->_type; }
+    WrapperBox* getWrapperBox() const;
+
 protected:
     void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
     void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
@@ -29,11 +37,9 @@ protected:
 private:
     void setColor(QColor color);
 
-    GraphicsBox* getParent() const;
-
     std::shared_ptr<Connection> connection;
     QGraphicsLineItem* tempLine = nullptr;
-    bool isInput;
+    Type _type;
 
 private slots:
     void on_Disconnect();
diff --git a/agui2/Graphics/GraphicsBox.cpp b/agui2/Graphics/GraphicsBox.cpp
index da59c5c9b4a5cb264d632116424beac4b40e7ecd..18fa0b144686d9d2ce3be28afec34de50f8db204 100644
--- a/agui2/Graphics/GraphicsBox.cpp
+++ b/agui2/Graphics/GraphicsBox.cpp
@@ -28,7 +28,7 @@ GraphicsBox::GraphicsBox(QString text, qreal x, qreal y, uint8_t inputs, uint8_t
     this->inputConnections.reserve(inputs);
     for (uint8_t i = 0; i < inputs; ++i)
     {
-        auto* box = new ConnectionBox(this, true);
+        auto* box = new ConnectionBox(this, ConnectionBox::Type::Input);
         box->setPos(this->m_boundRect.left(), this->m_boundRect.top() + ((i + 1) * this->m_boundRect.height()) / float(inputs + 1));
         this->inputConnections.push_back(box);
     }
@@ -36,7 +36,7 @@ GraphicsBox::GraphicsBox(QString text, qreal x, qreal y, uint8_t inputs, uint8_t
     this->outputConnections.reserve(outputs);
     for (uint8_t i = 0; i < outputs; ++i)
     {
-        auto* box = new ConnectionBox(this, false);
+        auto* box = new ConnectionBox(this, ConnectionBox::Type::Output);
         box->setPos(this->m_boundRect.right(), this->m_boundRect.top() + ((i + 1) * this->m_boundRect.height()) / float(outputs + 1));
         this->outputConnections.push_back(box);
     }
diff --git a/agui2/Graphics/GraphicsBox.h b/agui2/Graphics/GraphicsBox.h
index 10870b613dabcae75c1a43f6ffae75319faf4554..b47fecfa73133ee5fbebba936385b9a6b133af8c 100644
--- a/agui2/Graphics/GraphicsBox.h
+++ b/agui2/Graphics/GraphicsBox.h
@@ -19,6 +19,8 @@ class GraphicsBox : public QGraphicsObject
 {
     Q_OBJECT
 public:
+    friend class WrapperBox;
+
     explicit GraphicsBox(QString text, qreal x = 0, qreal y = 0, uint8_t inputs = 1, uint8_t outputs = 1);
     ~GraphicsBox() override;
 
@@ -30,7 +32,7 @@ public:
     QRectF boundingRect() const override;
     QPointF getConnectionOrigin();
     virtual QPointF getConnectionTarget( GraphicsConnection* connection );
-    friend class WrapperBox;
+    WrapperBox* getWrapperBox() const { return this->m_wrapper; }
 protected:
     QFont m_font;
     QColor m_color;