diff --git a/src/core/Main.cc b/src/core/Main.cc
index c170e63..b6fa5f1 100644
--- a/src/core/Main.cc
+++ b/src/core/Main.cc
@@ -18,7 +18,6 @@
 static size_t configitems;
 static unsigned int taskbar;
 static std::list<App *> list;
-static std::list<App *>::iterator it;
 static App *p;
 
 static Bar *barra;
@@ -69,8 +68,7 @@ int main(int argc, char **argv)
 
         if (list.size() != 0)
         {
-            it = list.begin();
-            p = (*it);
+            p = *list.begin();
         }
         else
         {
@@ -440,7 +438,6 @@ int mapIcons()
     {
 	list.pop_back();
 	((SuperBar *)barra)->removeIcon();
-	it--;
     }
     // add currently running tasks to the list
     if ( (taskbar) && 
@@ -481,15 +478,17 @@ int mapIcons()
 	    }
 	}
     }
-    //if this is not an initial run
-    if (!firstrun)
-        // and we added no windows
-	if ((size_t)list.size() == configitems)
-	    //then there is no need to add icons
+
+    // if this is not an initial run and we added no windows
+    // then there is no need to add icons
+    if (!firstrun && (size_t)list.size() == configitems)
 	    return 0;
-    for (it++; it != list.end(); it++)
+
+    std::list<App *>::iterator appsIt = list.begin();
+    while ((size_t)std::distance(list.begin(), ++appsIt) < configitems);
+    while (++appsIt != list.end())
     {
-        p = (*it);
+        p = *appsIt;
         try
             {
         	if (p->getIconName() != "")
@@ -518,8 +517,7 @@ int mapIcons()
         }
 	(void) XSetErrorHandler(oldXHandler);
 	barra->scale();
-	if (firstrun)
-	    it--;
+
 	return 0;
 }
 
