diff --git a/compiler2/Value.cc b/compiler2/Value.cc
index b5e219a90fd67734210bdb8059293045b3fec5e4..a03df6b01b7814b930f98fc2516c2aa374c12f71 100644
--- a/compiler2/Value.cc
+++ b/compiler2/Value.cc
@@ -10575,17 +10575,19 @@ error:
       }
       label_r1:
       // no break
-    case OPTYPE_UNDEF_RUNNING: // r1 [r2] b4
+    case OPTYPE_TMR_READ: {     // r1
+      Common::Assignment *ass = u.expr.r1->get_refd_assignment();
+      self_ref |= (ass == lhs);
+      break; }
+    case OPTYPE_UNDEF_RUNNING: { // r1 [r2] b4
       if (u.expr.r2 != NULL) {
-        Common::Assignment *ass = u.expr.r2->get_refd_assignment();
-        self_ref |= (ass == lhs);
+        Common::Assignment *ass2 = u.expr.r2->get_refd_assignment();
+        self_ref |= (ass2 == lhs);
       }
-      // no break
-    case OPTYPE_TMR_READ: {     // r1
       Common::Assignment *ass = u.expr.r1->get_refd_assignment();
       self_ref |= (ass == lhs);
       break; }
-
+    
     case OPTYPE_ISCHOSEN_T: // t1 i2
     case OPTYPE_ISBOUND: // ti1
     case OPTYPE_ISVALUE: // ti1
diff --git a/compiler2/ttcn3/Statement.cc b/compiler2/ttcn3/Statement.cc
index 3db41091534cc4bfad9959437f078a65abf318b9..0fd310782d83e0b61498f89c4a54cd4b429f7168 100644
--- a/compiler2/ttcn3/Statement.cc
+++ b/compiler2/ttcn3/Statement.cc
@@ -653,6 +653,8 @@ namespace Ttcn {
       break;
     case S_STOP_COMP:
     case S_KILL:
+      delete comp_op.compref;
+      break;
     case S_KILLED:
       delete comp_op.compref;
       delete comp_op.index_redirect;
@@ -1349,6 +1351,9 @@ namespace Ttcn {
   {
     switch (statementtype) {
     case S_DONE:
+      comp_op.donereturn.donematch = NULL;
+      comp_op.donereturn.redirect = NULL;
+      // no break
     case S_KILLED:
       comp_op.compref = 0;
       comp_op.any_or_all = p_anyall;
@@ -1814,6 +1819,8 @@ namespace Ttcn {
       break;
     case S_STOP_COMP:
     case S_KILL:
+      if (comp_op.compref) comp_op.compref->set_my_scope(p_scope);
+      break;
     case S_KILLED:
       if (comp_op.compref) comp_op.compref->set_my_scope(p_scope);
       if (comp_op.index_redirect != NULL) {
@@ -2087,6 +2094,8 @@ namespace Ttcn {
       break;
     case S_STOP_COMP:
     case S_KILL:
+      if (comp_op.compref) comp_op.compref->set_fullname(p_fullname+".compref");
+      break;
     case S_KILLED:
       if (comp_op.compref) comp_op.compref->set_fullname(p_fullname+".compref");
       if (comp_op.index_redirect != NULL) {
@@ -5683,6 +5692,8 @@ error:
       break;
     case S_STOP_COMP:
     case S_KILL:
+      if (comp_op.compref) comp_op.compref->set_code_section(p_code_section);
+      break;
     case S_KILLED:
       if (comp_op.compref) comp_op.compref->set_code_section(p_code_section);
       if (comp_op.index_redirect != NULL) {