diff --git a/window.cpp b/window.cpp
index b5d5755efd5d0966e7b226bee840cf45d203621f..9f27856e35481b99981cbdb40b91937fd7978f32 100644
--- a/window.cpp
+++ b/window.cpp
@@ -76,32 +76,30 @@ void Window::solveButtonClicked()
     while (1)
     {
         std::vector<Cell *> b; // vector of cells with least entropy
+        b.reserve(81);
         int minEtropy = 10;
-        for (int x = 0; x < 9; x++) // loop through all cells and fill list b --> this could be optimzed
+        for (auto &cell : grid)
         {
-            for (int y = 0; y < 9; y++)
+            if (cell.collapsed)
+                continue;
+            else if (cell.possibleStates < minEtropy)
             {
-                if (grid[x + y * 9].collapsed)
-                    continue;
-                else if (grid[x + y * 9].possibleStates < minEtropy)
-                {
-                    minEtropy = grid[x + y * 9].possibleStates;
-                    b.clear();
-                    b.push_back(&grid[x + y * 9]);
-                }
-                else if (grid[x + y * 9].possibleStates == minEtropy)
-                {
-                    b.push_back(&grid[x + y * 9]);
-                }
+                minEtropy = cell.possibleStates;
+                b.clear();
+                b.push_back(&cell);
+            }
+            else if (cell.possibleStates == minEtropy)
+            {
+                b.push_back(&cell);
             }
         }
+
         if (b.size() == 0) // if b is empty -> solved
-        {
             return;
-        }
-        else if (minEtropy == 0) 
+
+        else if (minEtropy == 0)
         {
-            while (hist.size()>0)
+            while (hist.size() > 0)
             {
                 hist.back()->collapsedCellClicked();
                 hist.pop_back();