diff --git a/cfel_cxi.py b/cfel_cxi.py
index db8d11dea00b39e84e8ff32a3b14d4fe4bcfd876..fc13c46ba8b93f33eaa89da7665f59bdec2170ae 100644
--- a/cfel_cxi.py
+++ b/cfel_cxi.py
@@ -274,9 +274,9 @@ class CXIWriter:
             raise RuntimeError('Adding stacks to the writer is not possible after initialization.')
 
         for entry in self._cxi_stacks:
-            if path == entry.path:
+            if path == self._cxi_stacks[entry].path:
                 if overwrite is True:
-                    del (self._cxi_stacks[name])
+                    del (self._cxi_stacks[entry])
                 else:
                     raise RuntimeError('Cannot write the entry. Data is already present at the specified path.')