Index: common/MessageProcessor.cpp
===================================================================
--- common/MessageProcessor.cpp	(revision 5755e68062e5e401a5587987b6271800b1dda233)
+++ common/MessageProcessor.cpp	(revision 6b641af913b64d36eed341590bb696959ad650c3)
@@ -35,4 +35,7 @@
    int ret =  recvfrom(sock, (char*)msg, sizeof(NETWORK_MSG), 0, (struct sockaddr *)source, &socklen);
 
+   if (ret == -1)
+      return ret;
+
    // add id to the NETWORK_MSG struct
    if (msg->type == MSG_TYPE_ACK) {
@@ -41,6 +44,5 @@
          sentMessages[msg->id].isAcked = true;
          sentMessages[msg->id].timeAcked = getCurrentMillis();
-      }else
-         cout << "Received old ack" << endl;
+      }
 
       return -1; // don't do any further processing
@@ -75,7 +77,16 @@
 
    while (it != sentMessages.end()) {
-      if (it->second.isAcked && (getCurrentMillis() - it->second.timeAcked) > 1000)
-         sentMessages.erase(it++);
-      else
+      if (it->second.isAcked) {
+//         cout << "Found acked message" << endl;
+//         cout << "time acked" << it->second.timeAcked << endl;
+//         cout << "cur time" << getCurrentMillis() << endl;
+         if ((getCurrentMillis() - it->second.timeAcked) > 1000) {
+            cout << "Message was acked. time to delete it" << endl;
+            cout << "old map size" << sentMessages.size() << endl;
+            sentMessages.erase(it++);
+            cout << "new map size" << sentMessages.size() << endl;
+         }else
+            it++;
+      }else
          it++;
    }
