diff --git a/src/capture/capture_base.cpp b/src/capture/capture_base.cpp
index 5d2fb35e045245204061a4d4d42a602acf166de1..1dde6230203c92faf50d64b76af917eb7f56e1f5 100644
--- a/src/capture/capture_base.cpp
+++ b/src/capture/capture_base.cpp
@@ -315,6 +315,7 @@ void CaptureBase::move(FrameBasePtr _frm_ptr)
 
 void CaptureBase::link(FrameBasePtr _frm_ptr)
 {
+    assert(!is_removing_ && "linking a removed capture");
     assert(this->getFrame() == nullptr && "linking a capture already linked");
 
     if(_frm_ptr)
diff --git a/src/factor/factor_base.cpp b/src/factor/factor_base.cpp
index 59f1961d576b7dc9d979eab662d86e4e37a80de3..ba66157fef97f3de1cdcc24990275526f0da4da2 100644
--- a/src/factor/factor_base.cpp
+++ b/src/factor/factor_base.cpp
@@ -49,7 +49,7 @@ void FactorBase::remove()
     if (!is_removing_)
     {
         is_removing_ = true;
-        FactorBasePtr this_c = shared_from_this(); // keep this alive while removing it
+        FactorBasePtr this_fac = shared_from_this(); // keep this alive while removing it
         FeatureBasePtr f = feature_ptr_.lock();
         if (f)
         {
@@ -59,13 +59,13 @@ void FactorBase::remove()
         }
         // add factor to be removed from solver
         if (getProblem() != nullptr)
-            getProblem()->notifyFactor(shared_from_this(),REMOVE);
+            getProblem()->notifyFactor(this_fac,REMOVE);
 
         // remove other: {Frame, Capture, Feature, Landmark}
         FrameBasePtr frm_o = frame_other_ptr_.lock();
         if (frm_o)
         {
-            frm_o->removeConstrainedBy(shared_from_this());
+            frm_o->removeConstrainedBy(this_fac);
             if (frm_o->getConstrainedByList().empty() && frm_o->getCaptureList().empty())
                 frm_o->remove();
         }
@@ -73,7 +73,7 @@ void FactorBase::remove()
         CaptureBasePtr cap_o = capture_other_ptr_.lock();
         if (cap_o)
         {
-            cap_o->removeConstrainedBy(shared_from_this());
+            cap_o->removeConstrainedBy(this_fac);
             if (cap_o->getConstrainedByList().empty() && cap_o->getFeatureList().empty())
                 cap_o->remove();
         }
@@ -81,7 +81,7 @@ void FactorBase::remove()
         FeatureBasePtr ftr_o = feature_other_ptr_.lock();
         if (ftr_o)
         {
-            ftr_o->removeConstrainedBy(shared_from_this());
+            ftr_o->removeConstrainedBy(this_fac);
             if (ftr_o->getConstrainedByList().empty() && ftr_o->getFactorList().empty())
                 ftr_o->remove();
         }
@@ -89,7 +89,7 @@ void FactorBase::remove()
         LandmarkBasePtr lmk_o = landmark_other_ptr_.lock();
         if (lmk_o)
         {
-            lmk_o->removeConstrainedBy(shared_from_this());
+            lmk_o->removeConstrainedBy(this_fac);
             if (lmk_o->getConstrainedByList().empty())
                 lmk_o->remove();
         }
@@ -143,6 +143,7 @@ void FactorBase::setStatus(FactorStatus _status)
 
 void FactorBase::link(FeatureBasePtr _ftr_ptr)
 {
+    assert(!is_removing_ && "linking a removed factor");
     assert(this->getFeature() == nullptr && "linking an already linked factor");
 
     // not link if nullptr