diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index e613e2125c9878ecffc9e176f952301d9cad2b6a..1626938abedc5f22844fbb329f40776c0771e077 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
@@ -333,6 +333,9 @@ public class Controller
                         Channels.fireExceptionCaught(ctx.getChannel(), ex);
                     }
                 }
+
+                // Flush all flow-mods/packet-out generated from this "train"
+                OFSwitchImpl.flush_all();
             }
         }
         
diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java
index 0bda63c7a4d33a21f566743d5943d2631cfb76f8..44fffddc05a17e37a8575e43502c6c5f229b4c5d 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java
@@ -142,15 +142,16 @@ public class OFSwitchImpl implements IOFSwitch {
         Map<OFSwitchImpl,List<OFMessage>> msg_buffer_map = local_msg_buffer.get();
         List<OFMessage> msg_buffer = msg_buffer_map.get(this);
         if (msg_buffer == null) {
-                msg_buffer = new ArrayList<OFMessage>();
-                msg_buffer_map.put(this, msg_buffer);
+            msg_buffer = new ArrayList<OFMessage>();
+            msg_buffer_map.put(this, msg_buffer);
         }
 
-        // handleOutgoingMessage is done at the time of flushing the buffer
+        this.floodlightProvider.handleOutgoingMessage(this, m, bc);
         msg_buffer.add(m);
+
         if ((msg_buffer.size() >= Controller.BATCH_MAX_SIZE) ||
             ((m.getType() != OFType.PACKET_OUT) && (m.getType() != OFType.FLOW_MOD))) {
-            this.write(msg_buffer, bc);
+            this.write(msg_buffer);
             msg_buffer.clear();
         }
     }
@@ -159,6 +160,10 @@ public class OFSwitchImpl implements IOFSwitch {
         for (OFMessage m : msglist) {
             this.floodlightProvider.handleOutgoingMessage(this, m, bc);
         }
+        this.write(msglist);
+    }
+
+    public void write(List<OFMessage> msglist) throws IOException {
         this.channel.write(msglist);
     }
     
@@ -389,6 +394,22 @@ public class OFSwitchImpl implements IOFSwitch {
         return timedCache;
 	}
 
+    public static void flush_all() {
+        Map<OFSwitchImpl,List<OFMessage>> msg_buffer_map = local_msg_buffer.get();
+        for (OFSwitchImpl sw : msg_buffer_map.keySet()) {
+            List<OFMessage> msglist = msg_buffer_map.get(sw);
+            if (msglist.size() > 0) {
+                try {
+                    sw.write(msglist);
+                } catch (IOException e) {
+                    // TODO: log exception
+                    e.printStackTrace();
+                }
+                msglist.clear();
+            }
+        }
+    }
+
     /**
      * Return a lock that need to be held while processing a message. Multiple threads
      * can hold this lock.