diff --git a/examples/server.js b/examples/server.js
index 4646901..a19b781 100644
--- a/examples/server.js
+++ b/examples/server.js
@@ -6,6 +6,7 @@ var options = {
   motd: 'Vox Industries',
   'max-players': 127,
   port: 25565,
+  'online-mode': false,
 };
 
 var server = mc.createServer(options);
diff --git a/index.js b/index.js
index 9b003e9..fe02726 100644
--- a/index.js
+++ b/index.js
@@ -36,6 +36,7 @@ function createServer(options) {
   var serverKey = ursa.generatePrivateKey(1024);
 
   var server = new Server(options);
+  server.playerCount = 0;
   server.onlineModeExceptions = {};
   server.maxPlayers = maxPlayers;
   server.on("connection", function(client) {
@@ -191,6 +192,10 @@ function createServer(options) {
       clearTimeout(loginKickTimer);
       loginKickTimer = null;
 
+      server.playerCount += 1;
+      client.once('end', function() {
+        server.playerCount -= 1;
+      });
       server.emit('login', client);
     }
   });
diff --git a/lib/server.js b/lib/server.js
index 62d1c40..07410d0 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -9,8 +9,6 @@ module.exports = Server;
 function Server() {
   EventEmitter.call(this);
 
-  this.playerCount = 0
-
   this.socketServer = null;
   this.cipher = null;
   this.decipher = null;
@@ -26,9 +24,9 @@ Server.prototype.listen = function(port, host) {
     var client = new Client(true);
     client._end = client.end;
     client.end = function end(endReason) {
-        client.write(0xff, {reason: endReason});
-        client._end(endReason);
-    }
+      client.write(0xff, {reason: endReason});
+      client._end(endReason);
+    };
     client.id = nextId++;
     self.clients[client.id] = client;
     client.on('error', function(err) {
@@ -36,9 +34,7 @@ Server.prototype.listen = function(port, host) {
     });
     client.on('end', function() {
       delete self.clients[client.id];
-      this.playerCount -= 1;
     });
-    this.playerCount += 1;
     client.setSocket(socket);
     self.emit('connection', client);
   });