diff --git a/src/problem/problem.cpp b/src/problem/problem.cpp
index 8d5858a6e0045372d9dfb75a702f29c018ba9d22..f2fcb9096396bfd5d3913e861bd91c7a4bc1c6c2 100644
--- a/src/problem/problem.cpp
+++ b/src/problem/problem.cpp
@@ -481,7 +481,15 @@ VectorComposite Problem::getState(const StateStructure& _structure) const
         for (const auto& pair_key_vec : prc_state)
         {
             if (state.count(pair_key_vec.first) == 0) // Only write once. This gives priority to processors with more priority
-                state.insert(pair_key_vec);
+            {  
+              state.insert(pair_key_vec);
+            }
+        }
+
+        //If all keys are filled return
+        if (state.size() == structure.size())
+        {
+            return state;
         }
     }
 
@@ -531,6 +539,12 @@ VectorComposite Problem::getState (const TimeStamp& _ts, const StateStructure& _
             if (state.count(pair_key_vec.first) == 0) // Only write once. This gives priority to processors with more priority
                 state.insert(pair_key_vec);
         }
+
+        //If all keys are filled return
+        if (state.size() == structure.size())
+        {
+            return state;
+        }
     }
 
     // check for empty blocks and fill them with the closest KF to ts, with the prior, or with zeros in the worst case