diff --git a/MeshLib/Elements/Element.cpp b/MeshLib/Elements/Element.cpp
index 9806066e1eda0b42fcbac9d389cb9833bf8c40d2..fb834b37fdcccd2adf6a31d58afb9f4f5194f01b 100644
--- a/MeshLib/Elements/Element.cpp
+++ b/MeshLib/Elements/Element.cpp
@@ -41,7 +41,8 @@ void Element::setNeighbor(Element* neighbor, unsigned const face_id)
 
 std::optional<unsigned> Element::addNeighbor(Element* e)
 {
-    if (e == this || e == nullptr || e->getDimension() != this->getDimension())
+    const unsigned dim(this->getDimension());
+    if (e == this || e == nullptr || e->getDimension() != dim)
     {
         return std::optional<unsigned>();
     }
@@ -56,7 +57,6 @@ std::optional<unsigned> Element::addNeighbor(Element* e)
     const unsigned eNodes(e->getNumberOfBaseNodes());
     const Node* const* e_nodes = e->getNodes();
     unsigned count(0);
-    const unsigned dim(this->getDimension());
     for (unsigned i(0); i < nNodes; i++)
     {
         for (unsigned j(0); j < eNodes; j++)