diff --git a/src/main/java/ui/tmlad/TMLADEncrypt.java b/src/main/java/ui/tmlad/TMLADEncrypt.java
index 5648f6a7dc22e38fb9098670478f746d43852dfa..3b454c64a4ba2815f07d155ff14d2d1f309829df 100755
--- a/src/main/java/ui/tmlad/TMLADEncrypt.java
+++ b/src/main/java/ui/tmlad/TMLADEncrypt.java
@@ -279,50 +279,54 @@ public class TMLADEncrypt extends TADComponentWithoutSubcomponents/* Issue #69 T
     }
 
     private void setSecPatternName(String s) {
-        TURTLEPanel tpCur = tdp.getMainGUI().getCurrentTURTLEPanel();
-        for (TDiagramPanel t : tpCur.getPanels()) {
-            if (t instanceof TMLActivityDiagramPanel) {
-                for (TGComponent t2 : t.getComponentList()) {
-                    if (t2 instanceof TMLADWriteChannel) {
-                        TMLADWriteChannel twc = (TMLADWriteChannel) t2;
-                        if (twc.getSecurityContext().equals(securityContext)) {
-                            twc.setSecurityContext(s);
+        if (tdp.getMainGUI() != null && tdp.getMainGUI().getCurrentTURTLEPanel() != null) {
+            TURTLEPanel tpCur = tdp.getMainGUI().getCurrentTURTLEPanel();
+            for (TDiagramPanel t : tpCur.getPanels()) {
+                if (t instanceof TMLActivityDiagramPanel) {
+                    for (TGComponent t2 : t.getComponentList()) {
+                        if (t2 instanceof TMLADWriteChannel) {
+                            TMLADWriteChannel twc = (TMLADWriteChannel) t2;
+                            if (twc.getSecurityContext().equals(securityContext)) {
+                                twc.setSecurityContext(s);
+                            }
                         }
-                    }
 
-                    if (t2 instanceof TMLADReadChannel) {
-                        TMLADReadChannel trc = (TMLADReadChannel) t2;
-                        if (trc.getSecurityContext().equals(securityContext)) {
-                            trc.setSecurityContext(s);
+                        if (t2 instanceof TMLADReadChannel) {
+                            TMLADReadChannel trc = (TMLADReadChannel) t2;
+                            if (trc.getSecurityContext().equals(securityContext)) {
+                                trc.setSecurityContext(s);
+                            }
                         }
-                    }
 
-                    if (t2 instanceof TMLADDecrypt) {
-                        TMLADDecrypt td = (TMLADDecrypt) t2;
-                        if (td.getSecurityContext().equals(securityContext)) {
-                            td.securityContext = s;
+                        if (t2 instanceof TMLADDecrypt) {
+                            TMLADDecrypt td = (TMLADDecrypt) t2;
+                            if (td.getSecurityContext().equals(securityContext)) {
+                                td.securityContext = s;
+                            }
                         }
                     }
                 }
             }
-        }
-        for (TURTLEPanel tp : tdp.getMainGUI().tabs) {
-            if (tp instanceof TMLArchiPanel) {
-                TMLArchiDiagramPanel archPanel = ((TMLArchiPanel) tp).tmlap;
-                for (TGComponent tg : archPanel.getComponentList()) {
-                    if (tg instanceof TMLArchiCommunicationNode) {
-                        TMLArchiCommunicationNode tacn = (TMLArchiCommunicationNode) tg;
-                        for (TGComponent tgc : tacn.getRecursiveAllInternalComponent()) {
-                            if (tgc instanceof TMLArchiKey) {
-                                TMLArchiKey tak = (TMLArchiKey) tgc;
-                                if (tak.getValue().equals(securityContext)) {
-                                    tak.setValue(s);
+            for (TURTLEPanel tp : tdp.getMainGUI().tabs) {
+                if (tp instanceof TMLArchiPanel) {
+                    TMLArchiDiagramPanel archPanel = ((TMLArchiPanel) tp).tmlap;
+                    if (archPanel != null) {
+                        for (TGComponent tg : archPanel.getComponentList()) {
+                            if (tg instanceof TMLArchiCommunicationNode) {
+                                TMLArchiCommunicationNode tacn = (TMLArchiCommunicationNode) tg;
+                                for (TGComponent tgc : tacn.getRecursiveAllInternalComponent()) {
+                                    if (tgc instanceof TMLArchiKey) {
+                                        TMLArchiKey tak = (TMLArchiKey) tgc;
+                                        if (tak.getValue().equals(securityContext)) {
+                                            tak.setValue(s);
+                                        }
+                                    }
                                 }
                             }
                         }
+                        archPanel.repaint();
                     }
                 }
-                archPanel.repaint();
             }
         }
     }
diff --git a/src/main/java/ui/tmlcompd/TMLCPrimitivePort.java b/src/main/java/ui/tmlcompd/TMLCPrimitivePort.java
index 3fbd858f09f5bf0c83ccb9f39aab3e038d4a2aaa..7bcb849e2df7d33e2834381db65c7e4fa1248082 100755
--- a/src/main/java/ui/tmlcompd/TMLCPrimitivePort.java
+++ b/src/main/java/ui/tmlcompd/TMLCPrimitivePort.java
@@ -967,46 +967,50 @@
      public void setPortName(String s) {
          List<TMLCPrimitivePort> listConnectedPorts = ((TMLComponentTaskDiagramPanel) tdp).getPortsConnectedTo(this,
                  tdp.getAllComponentList());
-         for (TURTLEPanel tp : tdp.getMainGUI().tabs) {
-             if (tp instanceof TMLArchiPanel) {
-                 TMLArchiDiagramPanel archPanel = ((TMLArchiPanel) tp).tmlap;
-                 for (TGComponent tg : archPanel.getComponentList()) {
-                     if (tg instanceof TMLArchiPortArtifact) {
-                         if (!isOrigin) {
-                             TMLArchiPortArtifact portArt = (TMLArchiPortArtifact) tg;
-                             if (portArt.getPortName().equals(commName) && portArt.getReferenceCommunicationName().equals(tdp.tp.getNameOfTab())) {
-                                 portArt.setPortName(s);
-                             }
-                         }
-                     } else if (tg instanceof TMLArchiCommunicationNode) {
-                         TMLArchiCommunicationNode tacn = (TMLArchiCommunicationNode) tg;
-                         for (TGComponent tgc : tacn.getRecursiveAllInternalComponent()) {
-                             if (tgc instanceof TMLArchiPortArtifact) {
+         if (tdp.getMainGUI() != null && tdp.getMainGUI().getTabs() != null) {
+             for (TURTLEPanel tp : tdp.getMainGUI().getTabs()) {
+                 if (tp instanceof TMLArchiPanel) {
+                     TMLArchiDiagramPanel archPanel = ((TMLArchiPanel) tp).tmlap;
+                     if (archPanel != null) {
+                         for (TGComponent tg : archPanel.getComponentList()) {
+                             if (tg instanceof TMLArchiPortArtifact) {
                                  if (!isOrigin) {
-                                     TMLArchiPortArtifact portArt = (TMLArchiPortArtifact) tgc;
+                                     TMLArchiPortArtifact portArt = (TMLArchiPortArtifact) tg;
                                      if (portArt.getPortName().equals(commName) && portArt.getReferenceCommunicationName().equals(tdp.tp.getNameOfTab())) {
                                          portArt.setPortName(s);
                                      }
                                  }
-                             } else if (tgc instanceof TMLArchiCommunicationArtifact) {
-                                 TMLArchiCommunicationArtifact comArt = (TMLArchiCommunicationArtifact) tgc;
-                                 if (comArt.getReferenceCommunicationName().equals(tdp.tp.getNameOfTab())) {
-                                     for (TMLCPrimitivePort port2 : listConnectedPorts) {
-                                         String communicationName;
-                                         if (port2.getPortName().equals(commName)) {
-                                             communicationName = commName;
-                                         } else if (this.isOrigin) {
-                                             communicationName = commName + "__" + port2.getPortName();
-                                         } else {
-                                             communicationName = port2.getPortName() + "__" + commName;
+                             } else if (tg instanceof TMLArchiCommunicationNode) {
+                                 TMLArchiCommunicationNode tacn = (TMLArchiCommunicationNode) tg;
+                                 for (TGComponent tgc : tacn.getRecursiveAllInternalComponent()) {
+                                     if (tgc instanceof TMLArchiPortArtifact) {
+                                         if (!isOrigin) {
+                                             TMLArchiPortArtifact portArt = (TMLArchiPortArtifact) tgc;
+                                             if (portArt.getPortName().equals(commName) && portArt.getReferenceCommunicationName().equals(tdp.tp.getNameOfTab())) {
+                                                 portArt.setPortName(s);
+                                             }
                                          }
-                                         if (comArt.getCommunicationName().equals(communicationName)) {
-                                             if (port2.getPortName().equals(s)) {
-                                                 comArt.setCommunicationName(s);
-                                             } else if (this.isOrigin) {
-                                                 comArt.setCommunicationName(s + "__" + port2.getPortName());
-                                             } else {
-                                                 comArt.setCommunicationName(port2.getPortName() + "__" + s);
+                                     } else if (tgc instanceof TMLArchiCommunicationArtifact) {
+                                         TMLArchiCommunicationArtifact comArt = (TMLArchiCommunicationArtifact) tgc;
+                                         if (comArt.getReferenceCommunicationName().equals(tdp.tp.getNameOfTab())) {
+                                             for (TMLCPrimitivePort port2 : listConnectedPorts) {
+                                                 String communicationName;
+                                                 if (port2.getPortName().equals(commName)) {
+                                                     communicationName = commName;
+                                                 } else if (this.isOrigin) {
+                                                     communicationName = commName + "__" + port2.getPortName();
+                                                 } else {
+                                                     communicationName = port2.getPortName() + "__" + commName;
+                                                 }
+                                                 if (comArt.getCommunicationName().equals(communicationName)) {
+                                                     if (port2.getPortName().equals(s)) {
+                                                         comArt.setCommunicationName(s);
+                                                     } else if (this.isOrigin) {
+                                                         comArt.setCommunicationName(s + "__" + port2.getPortName());
+                                                     } else {
+                                                         comArt.setCommunicationName(port2.getPortName() + "__" + s);
+                                                     }
+                                                 }
                                              }
                                          }
                                      }
@@ -1014,8 +1018,8 @@
                              }
                          }
                      }
+                     archPanel.repaint();
                  }
-                 archPanel.repaint();
              }
          }