diff --git a/lib/client.js b/lib/client.js
index fb41c85..2131496 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -4,6 +4,7 @@ var net = require('net')
   , protocol = require('./protocol')
   , createPacketBuffer = protocol.createPacketBuffer
   , parsePacket = protocol.parsePacket
+  , debug = protocol.debug
 
 module.exports = Client;
 
@@ -78,6 +79,7 @@ Client.prototype.end = function(reason) {
 
 Client.prototype.write = function(packetId, params) {
   var buffer = createPacketBuffer(packetId, params, this.isServer);
+  debug("writing packetId " + packetId + " (0x" + packetId.toString(16) + ")");
   var out = this.encryptionEnabled ? new Buffer(this.cipher.update(buffer), 'binary') : buffer;
   this.socket.write(out);
 };
diff --git a/lib/protocol.js b/lib/protocol.js
index e91df4a..21be784 100644
--- a/lib/protocol.js
+++ b/lib/protocol.js
@@ -1,4 +1,5 @@
 var assert = require('assert');
+var util = require('util');
 
 var STRING_MAX_LENGTH = 240;
 
@@ -307,6 +308,14 @@ var packets = {
     { name: "global", type: "bool" }
   ],
   0x3e: [
+    { name: "soundName", type: "string" },
+    { name: "x", type: "int" },
+    { name: "y", type: "int" },
+    { name: "z", type: "int" },
+    { name: "volume", type: "float" },
+    { name: "pitch", type: "byte" }
+  ],
+  0x3f: [
     { name: "particleName", type: "string" },
     { name: "x", type: "float" },
     { name: "y", type: "float" },
@@ -317,14 +326,6 @@ var packets = {
     { name: "particleSpeed", type: "float" },
     { name: "particles", type: "int" }
   ],
-  0x3f: [
-    { name: "soundName", type: "string" },
-    { name: "x", type: "int" },
-    { name: "y", type: "int" },
-    { name: "z", type: "int" },
-    { name: "volume", type: "float" },
-    { name: "pitch", type: "byte" }
-  ],
   0x46: [
     { name: "reason", type: "byte" },
     { name: "gameMode", type: "byte" }
@@ -450,7 +451,7 @@ var packets = {
     { name: "name", type: "string" },
     { name: "prefix", type: "string" },
     { name: "suffix", type: "string" },
-    { name: "friendlyFire", type: "bool" },
+    { name: "friendlyFire", type: "byte" },
     { name: "players", type: "stringArray" }
   ],
   0xfa: [
@@ -500,6 +501,20 @@ var types = {
   'stringArray': [readStringArray, writeStringArray, sizeOfStringArray],
 };
 
+var debug;
+if (process.env.NODE_DEBUG && /(minecraft-protocol|mc-proto)/.test(process.env.NODE_DEBUG)) {
+  var pid = process.pid;
+  debug = function(x) {
+    // if console is not set up yet, then skip this.
+    if (!console.error)
+      return;
+    console.error('MC-PROTO: %d', pid,
+                  util.format.apply(util, arguments).slice(0, 500));
+  };
+} else {
+  debug = function() { };
+}
+
 function sizeOfByteArray32(value) {
   return 4 + value.length;
 }
@@ -1239,8 +1254,10 @@ function parsePacket(buffer, isServer) {
   var packetInfo = get(packetId, isServer);
   if (packetInfo == null) {
     return {
-      error: new Error("Unrecognized packetId: " + packetId)
+      error: new Error("Unrecognized packetId: " + packetId + " (0x" + packetId.toString(16) + ")")
     }
+  } else {
+    debug("read packetId " + packetId + " (0x" + packetId.toString(16) + ")");
   }
   var i, fieldInfo, read, readResults;
   for (i = 0; i < packetInfo.length; ++i) {
@@ -1266,11 +1283,12 @@ function parsePacket(buffer, isServer) {
 
 module.exports = {
   version: 60,
-  minecraftVersion: '1.5',
+  minecraftVersion: '1.5.1',
   sessionVersion: 13,
   parsePacket: parsePacket,
   createPacketBuffer: createPacketBuffer,
   STRING_MAX_LENGTH: STRING_MAX_LENGTH,
   packets: packets,
   get: get,
+  debug: debug,
 };