diff --git a/src/main/java/org/openflow/protocol/factory/BasicFactory.java b/src/main/java/org/openflow/protocol/factory/BasicFactory.java
index e0296e3f52fc59b9c898d12cbfe9597bc4e02e00..7b15e82612326158f0eb5184518c20b11be7ae65 100644
--- a/src/main/java/org/openflow/protocol/factory/BasicFactory.java
+++ b/src/main/java/org/openflow/protocol/factory/BasicFactory.java
@@ -115,17 +115,12 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
         } catch (Exception e) {
             /* Write the offending data along with the error message */
             data.resetReaderIndex();
-            int len = data.readableBytes();
-            StringBuffer sb = new StringBuffer();
-                for (int i=0 ; i<len; i++) {
-                    sb.append(String.format(" %02x", data.getUnsignedByte(i)));
-                    if (i%16 == 15) sb.append("\n");
-                }
-                String msg =
-                        "Message Parse Error for packet: " +  sb.toString() +
-                        "\nException: " + e.toString();
+            String msg =
+                    "Message Parse Error for packet:" +  dumpBuffer(data) +
+                    "\nException: " + e.toString();
+            data.resetReaderIndex();
 
-                throw new MessageParseException(msg, e);
+            throw new MessageParseException(msg, e);
         }
     }
 
@@ -283,4 +278,17 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
         return vendorData;
     }
 
+    public static String dumpBuffer(ChannelBuffer data) {
+        // NOTE: Reads all the bytes in buffer from current read offset.
+        // Set/Reset ReaderIndex if you want to read from a different location
+        int len = data.readableBytes();
+        StringBuffer sb = new StringBuffer();
+        for (int i=0 ; i<len; i++) {
+            if (i%32 == 0) sb.append("\n");
+            if (i%4 == 0) sb.append(" ");
+            sb.append(String.format("%02x", data.getUnsignedByte(i)));
+        }
+        return sb.toString();
+    }
+
 }
diff --git a/src/test/java/org/openflow/protocol/BasicFactoryTest.java b/src/test/java/org/openflow/protocol/BasicFactoryTest.java
index 05f8e124b1f847598b2346cfbbfad8acbb39fd33..6825008d98b0f9c0134b77a3f13dc39b54911fd7 100644
--- a/src/test/java/org/openflow/protocol/BasicFactoryTest.java
+++ b/src/test/java/org/openflow/protocol/BasicFactoryTest.java
@@ -74,7 +74,8 @@ public class BasicFactoryTest extends TestCase {
                 factory.parseMessage(bb);
         }
         catch(Exception e) {
-                TestCase.assertEquals(MessageParseException.class, e.getClass());
+            TestCase.assertEquals(MessageParseException.class, e.getClass());
         }
     }
+
 }