diff --git a/agui2/ALIB.pro b/agui2/ALIB.pro
index dbce2cd1b503aa708bb32dcf248f0af47fc809c6..e9a7bcd5919e40857943e3363de88a7fb59b726b 100644
--- a/agui2/ALIB.pro
+++ b/agui2/ALIB.pro
@@ -32,14 +32,20 @@ SOURCES += main.cpp\
     inputdialog.cpp \
     graphicsconnection.cpp \
     graphicsscene.cpp \
-    connectionhelper.cpp
+    connectionhelper.cpp \
+    modelbox.cpp \
+    inputgraphicsbox.cpp \
+    wrapperbox.cpp
 
 HEADERS  += mainwindow.h \
     graphicsbox.h \
     inputdialog.h \
     graphicsconnection.h \
     graphicsscene.h \
-    connectionhelper.h
+    connectionhelper.h \
+    modelbox.h \
+    inputgraphicsbox.h \
+    wrapperbox.h
 
 FORMS    += mainwindow.ui \
     inputdialog.ui
diff --git a/agui2/connectionhelper.cpp b/agui2/connectionhelper.cpp
index edcd8cb001596a41d9c296a6e32a877e9d4d44f7..24fd63dde339755968aba697417a3042d364ce8a 100644
--- a/agui2/connectionhelper.cpp
+++ b/agui2/connectionhelper.cpp
@@ -1,26 +1,29 @@
 #include "connectionhelper.h"
 
+#include <QGraphicsScene>
+
 ConnectionHelper &ConnectionHelper::getInstance()
 {
     static ConnectionHelper instance;
     return instance;
 }
 
-void ConnectionHelper::startConnection(GraphicsBox *origin)
+void ConnectionHelper::startConnection(WrapperBox *origin)
 {
     m_originBox = origin;
 }
 
-void ConnectionHelper::completeConnection(GraphicsBox *target)
+void ConnectionHelper::completeConnection(WrapperBox *target)
 {
     if( target == NULL || m_originBox == NULL )
     {
         m_originBox = NULL;
         return;
     }
-    m_Connection = new GraphicsConnection( m_originBox, target, NULL);
-    m_originBox->addOutConnection(m_Connection);
-    target->addInConnection(m_Connection);
+    m_Connection = new GraphicsConnection( m_originBox->getGraphics(), target->getGraphics(), NULL);
+    m_originBox->addOutput( target, m_Connection );
+    target->addInput( m_originBox, m_Connection );
+    m_originBox->getGraphics()->scene()->update();
     m_originBox = NULL;
 }
 
diff --git a/agui2/connectionhelper.h b/agui2/connectionhelper.h
index 3d273ecd2ea0979ce7a01b7bf05a6e3c5901855d..366845e7f85283c1e02b426378febb234ce9cabe 100644
--- a/agui2/connectionhelper.h
+++ b/agui2/connectionhelper.h
@@ -8,11 +8,11 @@ class ConnectionHelper
 {
 public:
     static ConnectionHelper &getInstance();
-    void startConnection( GraphicsBox * origin );
-    void completeConnection( GraphicsBox * target );
+    void startConnection(WrapperBox *origin );
+    void completeConnection( WrapperBox * target );
 private:
     GraphicsConnection* m_Connection;
-    GraphicsBox* m_originBox;
+    WrapperBox* m_originBox;
     ConnectionHelper();
 };
 
diff --git a/agui2/graphicsbox.cpp b/agui2/graphicsbox.cpp
index b346fd40fb4e8818d782d567542838ec0203575a..3029fef215bf1a75945adb5a0e1cc3dc4d4b86af 100644
--- a/agui2/graphicsbox.cpp
+++ b/agui2/graphicsbox.cpp
@@ -10,27 +10,25 @@
 #include "graphicsscene.h"
 #include "connectionhelper.h"
 
-GraphicsBox::GraphicsBox(QGraphicsItem * parent, QString text, qreal x, qreal y)
-    : QGraphicsObject(parent)
+GraphicsBox::GraphicsBox(QString text, qreal x, qreal y)
+    : QGraphicsObject( NULL )
 {
     m_text = text;
     setPos(x, y);
     setFlags(ItemIsMovable);
     setZValue(1);
 
+    setBoundingRectangle();
+}
+
+void GraphicsBox::setBoundingRectangle()
+{
     QPainter painter;
     m_font.setBold(true);
     m_font.setPixelSize(18);
     painter.setFont(m_font);
     m_boundRect = painter.fontMetrics().boundingRect(m_text);
     m_boundRect.adjust(-BOX_MARGIN, -BOX_MARGIN, BOX_MARGIN, BOX_MARGIN);
-
-    m_OutConnection = NULL;
-}
-
-GraphicsBox::~GraphicsBox()
-{
-    delete m_OutConnection;
 }
 
 QRectF GraphicsBox::boundingRect() const
@@ -46,6 +44,11 @@ void GraphicsBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
     painter->drawText(m_boundRect, Qt::AlignCenter, m_text );
 }
 
+void GraphicsBox::addOutput(GraphicsConnection *connection)
+{
+    m_OutConnection = connection;
+}
+
 QPointF GraphicsBox::getConnectionOrigin()
 {
     return QPointF(m_boundRect.right(), m_boundRect.center().y());
@@ -56,40 +59,14 @@ QPointF GraphicsBox::getConnectionTarget()
     return QPointF(m_boundRect.left(), m_boundRect.center().y());
 }
 
-bool GraphicsBox::addInConnection(GraphicsConnection *connection)
-{
-    m_InConnections.append(connection);
-}
-
-bool GraphicsBox::addOutConnection(GraphicsConnection *connection)
-{
-    m_OutConnection = connection;
-}
-
-void GraphicsBox::on_SetInput()
-{
-    InputDialog * inputDlg = new InputDialog();
-    inputDlg->setModal(true);
-    inputDlg->show();
-}
-
-void GraphicsBox::on_Connect()
+WrapperBox *GraphicsBox::wrapper()
 {
-    ConnectionHelper::getInstance().startConnection(this);
+    return m_wrapper;
 }
 
-void GraphicsBox::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
+void GraphicsBox::setWrapper(WrapperBox *wrapper)
 {
-    QMenu menu;
-    QAction * a;
-    a = menu.addAction("Set &Input");
-    QObject::connect(a,SIGNAL(triggered()), this, SLOT(on_SetInput()));
-    a = menu.addAction("Connect");
-    QObject::connect(a,SIGNAL(triggered()), this, SLOT(on_Connect()));
-    menu.addAction("Action 3");
-    menu.exec(event->screenPos());
-    ungrabMouse();
-    event->accept();
+    m_wrapper = wrapper;
 }
 
 void GraphicsBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
@@ -97,7 +74,7 @@ void GraphicsBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
     if( event->button() == Qt::LeftButton )
     {
         event->accept();
-        ConnectionHelper::getInstance().completeConnection( this );
+        ConnectionHelper::getInstance().completeConnection( m_wrapper );
     }
     this->QGraphicsItem::mouseReleaseEvent(event);
 }
diff --git a/agui2/graphicsbox.h b/agui2/graphicsbox.h
index 9409d7419c062f3cd0c4d023a8a6ad7cbe64ad41..7988372831e42d564f018284765ccfb603e82710 100644
--- a/agui2/graphicsbox.h
+++ b/agui2/graphicsbox.h
@@ -2,6 +2,7 @@
 #define GRAPHICSBOX_H
 
 #include "graphicsconnection.h"
+#include "wrapperbox.h"
 
 #include <QPainter>
 #include <QGraphicsItem>
@@ -9,40 +10,31 @@
 
 #define BOX_MARGIN 30
 
+class WrapperBox;
 class GraphicsConnection;
 
-enum BoxTypes
-{
-    BOX_INPUT,
-    BOX_OUTPUT,
-    BOX_SINGLE,
-    BOX_DOUBLE
-};
-
 class GraphicsBox : public QGraphicsObject
 {
     Q_OBJECT
+    void setBoundingRectangle();
 public:
-    GraphicsBox(QGraphicsItem * parent, QString text, qreal x, qreal y);
+    GraphicsBox(QString text, qreal x = 0, qreal y = 0);
     GraphicsBox(QGraphicsItem * parent): QGraphicsObject(parent) {}
-    virtual ~GraphicsBox();
-    QRectF boundingRect() const;
+    virtual ~GraphicsBox(){}
     void paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget);
+    void addOutput( GraphicsConnection* connection );
+    void addInput( GraphicsConnection* connection ) {}
+    QRectF boundingRect() const;
     QPointF getConnectionOrigin();
     QPointF getConnectionTarget();
-    bool addInConnection( GraphicsConnection* connection );
-    bool addOutConnection(GraphicsConnection* connection );
-private:
+    WrapperBox* wrapper();
+    void setWrapper( WrapperBox* wrapper );
+protected:
+    QFont m_font;
     QString m_text;
     QRectF m_boundRect;
-    QFont m_font;
-    QList<GraphicsConnection*> m_InConnections;
     GraphicsConnection* m_OutConnection;
-private slots:
-    void on_SetInput();
-    void on_Connect();
-protected:
-    void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+    WrapperBox* m_wrapper;
     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
 };
 
diff --git a/agui2/graphicsconnection.cpp b/agui2/graphicsconnection.cpp
index d1fb6296d11d2b3636361297f0b067d8d02f05e0..821b4bb3d17ea062e76096699df58b6f1b2be8fe 100644
--- a/agui2/graphicsconnection.cpp
+++ b/agui2/graphicsconnection.cpp
@@ -42,6 +42,8 @@ void GraphicsConnection::paint(QPainter *painter, const QStyleOptionGraphicsItem
                       midWidth, targetPoint.y());
     painter->drawLine(midWidth, targetPoint.y(),
                       targetPoint.x(), targetPoint.y());
+
+    // Debug bounding rectangle
     painter->setPen(QPen(Qt::red,1));
     painter->drawRect(*m_boundRect);
 }
@@ -72,7 +74,7 @@ void GraphicsConnection::recalculateBoundingRect(const QPointF & originPoint , c
 
     prepareGeometryChange();
     m_boundRect->setRect( x, y, width, height );
-    m_boundRect->adjust( -2, -2, 2, 2 );
+    m_boundRect->adjust( -1, -1, 1, 1 );
 }
 
 
diff --git a/agui2/inputgraphicsbox.cpp b/agui2/inputgraphicsbox.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e24ebf1e6bb8e60c7b6dfd994869e5638458b4ed
--- /dev/null
+++ b/agui2/inputgraphicsbox.cpp
@@ -0,0 +1,32 @@
+#include "inputgraphicsbox.h"
+#include "inputdialog.h"
+#include "connectionhelper.h"
+
+#include <QMenu>
+#include <QAction>
+#include <QObject>
+
+void InputGraphicsBox::on_SetInput()
+{
+    InputDialog * inputDlg = new InputDialog();
+    inputDlg->setModal(true);
+    inputDlg->show();
+}
+
+void InputGraphicsBox::on_Connect()
+{
+    ConnectionHelper::getInstance().startConnection( m_wrapper );
+}
+
+void InputGraphicsBox::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
+{
+    QMenu menu;
+    QAction * a;
+    a = menu.addAction("Set &Input");
+    QObject::connect(a,SIGNAL(triggered()), this, SLOT(on_SetInput()));
+    a = menu.addAction("Connect");
+    QObject::connect(a,SIGNAL(triggered()), this, SLOT(on_Connect()));
+    menu.exec(event->screenPos());
+    ungrabMouse();
+    event->accept();
+}
diff --git a/agui2/inputgraphicsbox.h b/agui2/inputgraphicsbox.h
new file mode 100644
index 0000000000000000000000000000000000000000..3cd2ad355cedb69921e8a10b017d52d09e77c241
--- /dev/null
+++ b/agui2/inputgraphicsbox.h
@@ -0,0 +1,21 @@
+#ifndef INPUTGRAPHICSBOX_H
+#define INPUTGRAPHICSBOX_H
+
+#include "graphicsbox.h"
+
+class GraphicsBox;
+
+class InputGraphicsBox : public GraphicsBox
+{
+    Q_OBJECT
+public:
+    InputGraphicsBox(qreal x = 0, qreal y = 0): GraphicsBox("Input", x, y) {}
+    virtual ~InputGraphicsBox() {}
+private slots:
+    void on_SetInput();
+    void on_Connect();
+protected:
+    void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+};
+
+#endif // INPUTGRAPHICSBOX_H
diff --git a/agui2/mainwindow.cpp b/agui2/mainwindow.cpp
index 9f748b1deccab517f55208a8dd81b961cebd4650..bdcf6f420bf16614b4c9767cf463aa6916800d80 100644
--- a/agui2/mainwindow.cpp
+++ b/agui2/mainwindow.cpp
@@ -8,6 +8,7 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include "inputdialog.h"
+#include "inputgraphicsbox.h"
 
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
@@ -19,12 +20,11 @@ MainWindow::MainWindow(QWidget *parent) :
 
     QBrush brush(Qt::blue);
     QPen pen(Qt::blue);
-//    scene->setSceneRect(0,0,700,500);
-    QGraphicsItem * input = new GraphicsBox(0, "Input", 0, 0);
-    scene->addItem(input);
-    QGraphicsItem * output = new GraphicsBox(0, "Output", 150, 0);
-    scene->addItem(output);
-    QObjectList list = scene->children();
+
+    WrapperBox * inputBox = new WrapperBox( new ModelBox( 0,1 ), new InputGraphicsBox( 0, 0 ) );
+    scene->addItem(inputBox->getGraphics());
+    WrapperBox * outputBox = new WrapperBox( new ModelBox( 1,0 ), new GraphicsBox( "Output" , 100, 0 ) );
+    scene->addItem(outputBox->getGraphics());
 }
 
 MainWindow::~MainWindow()
@@ -50,7 +50,6 @@ void MainWindow::on_OpenFileBtn_clicked()
     if (!filename.isEmpty())
     {
         std::string utf8_filename = filename.toUtf8().constData();
-//        automaton = new automaton::Automaton( alib::XmlDataFactory::fromFile( utf8_filename ));
         automaton::Automaton automaton_local = alib::XmlDataFactory::fromFile( utf8_filename );
         automaton = new automaton::Automaton(automaton_local);
     }
diff --git a/agui2/mainwindow.h b/agui2/mainwindow.h
index 6d6c8e4df42660963ab9faf6e4c82accd3cbdbe8..bfd6c3028bdc8606ec02359b5ccd9420225f2b2e 100644
--- a/agui2/mainwindow.h
+++ b/agui2/mainwindow.h
@@ -7,7 +7,7 @@
 #include <QGraphicsScene>
 #include <QGraphicsItem>
 
-#include "graphicsbox.h"
+#include "modelbox.h"
 #include "graphicsscene.h"
 
 namespace Ui {
@@ -31,8 +31,6 @@ private:
     Ui::MainWindow *ui;
     automaton::Automaton *automaton = NULL;
     GraphicsScene * scene;
-    QGraphicsRectItem * rect;
-    GraphicsBox * box;
 };
 
 #endif // MAINWINDOW_H
diff --git a/agui2/modelbox.cpp b/agui2/modelbox.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c58d951b2e8c533719a8caeff186d93fc40cb7c8
--- /dev/null
+++ b/agui2/modelbox.cpp
@@ -0,0 +1,20 @@
+#include "modelbox.h"
+#include "inputgraphicsbox.h"
+
+ModelBox::ModelBox(int maxInConnections, int maxOutConnections)
+    : m_maxInConnections( maxInConnections ), m_maxOutConnections( maxOutConnections )
+{
+}
+
+bool ModelBox::addOutput(ModelBox *target)
+{
+    if( !m_maxOutConnections || m_OutConnection != NULL )
+        return false;
+    m_OutConnection = target;
+    return true;
+}
+
+void ModelBox::setWrapper( WrapperBox* wrapper )
+{
+    m_wrapper = wrapper;
+}
diff --git a/agui2/modelbox.h b/agui2/modelbox.h
new file mode 100644
index 0000000000000000000000000000000000000000..63c7c8022ab77187770eda8c39556c54bb28578d
--- /dev/null
+++ b/agui2/modelbox.h
@@ -0,0 +1,26 @@
+#ifndef MODELBOX_H
+#define MODELBOX_H
+
+#include "graphicsbox.h"
+#include "wrapperbox.h"
+
+#include <QString>
+
+class GraphicsBox;
+class WrapperBox;
+
+class ModelBox
+{
+public:
+    ModelBox(int maxInConnections, int maxOutConnections );
+    bool addInput( ModelBox * origin ) { return false; }
+    bool addOutput( ModelBox * target );
+    void setWrapper( WrapperBox* wrapper );
+private:
+    WrapperBox* m_wrapper;
+    const int m_maxInConnections;
+    const int m_maxOutConnections;
+    ModelBox * m_OutConnection;
+};
+
+#endif // MODELBOX_H
diff --git a/agui2/wrapperbox.cpp b/agui2/wrapperbox.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5c0a7faca901cdbbffff8d789b1c13f40893865f
--- /dev/null
+++ b/agui2/wrapperbox.cpp
@@ -0,0 +1,48 @@
+#include "wrapperbox.h"
+
+WrapperBox::WrapperBox( ModelBox * model, GraphicsBox * graphics ) :
+    m_model( model ), m_graphics( graphics )
+{
+    model->setWrapper( this );
+    graphics->setWrapper( this );
+}
+
+WrapperBox::~WrapperBox()
+{
+    delete m_model;
+    delete m_graphics;
+}
+
+bool WrapperBox::addInput(WrapperBox *origin, GraphicsConnection *connection)
+{
+    if( !m_model->addInput( origin->getModel() ) )
+        return false;
+    m_graphics->addInput( connection );
+    return true;
+}
+
+bool WrapperBox::addOutput(WrapperBox *target, GraphicsConnection *connection)
+{
+    if( !m_model->addOutput( target->getModel() ))
+        return false;
+    m_graphics->addOutput( connection );
+    return true;
+}
+
+ModelBox *WrapperBox::getModel()
+{
+    return m_model;
+}
+
+GraphicsBox *WrapperBox::getGraphics()
+{
+    return m_graphics;
+}
+
+
+
+
+
+
+
+
diff --git a/agui2/wrapperbox.h b/agui2/wrapperbox.h
new file mode 100644
index 0000000000000000000000000000000000000000..9de898e0d3323ebb2048b430f1e46a79bb7d38bd
--- /dev/null
+++ b/agui2/wrapperbox.h
@@ -0,0 +1,26 @@
+#ifndef WRAPPERBOX_H
+#define WRAPPERBOX_H
+
+#include "modelbox.h"
+#include "graphicsbox.h"
+#include "graphicsconnection.h"
+
+class ModelBox;
+class GraphicsBox;
+class GraphicsConnection;
+
+class WrapperBox
+{
+public:
+    WrapperBox(ModelBox *model, GraphicsBox *graphics);
+    ~WrapperBox();
+    bool addInput( WrapperBox * origin, GraphicsConnection * connection );
+    bool addOutput( WrapperBox * target, GraphicsConnection * connection );
+    ModelBox *getModel();
+    GraphicsBox *getGraphics();
+private:
+    ModelBox *m_model;
+    GraphicsBox *m_graphics;
+};
+
+#endif // WRAPPERBOX_H