diff --git a/common/lkt.js b/common/lkt.js
index 662b91833257b3245667a8ffe232ab6cc685ea19..5512d0143c983803416c8bc066104ded6c7d4534 100644
--- a/common/lkt.js
+++ b/common/lkt.js
@@ -20,42 +20,50 @@ class LktClient {
             writable: true
         };
 
-        logger.log("debug", "Creating the lektor client");
+        logger.debug("Creating the lektor client");
         this.m_socket.setTimeout(10);
         this.m_socket.setEncoding('utf8');
         this.m_socket.on("timeout", () => {
-            logger.log("error", `Got timeout while connecting to localhost:${this.m_port}`);
+            logger.error(`Got timeout while connecting to localhost:${this.m_port}`);
             this.m_socket.end();
         });
 
         this.m_socket.on("ready", () => {
-            logger.log("debug", `Ready to use socker with localhost:${this.m_port}`);
+            logger.debug(`Ready to use socker with localhost:${this.m_port}`);
             this.m_online = true;
         });
 
         this.m_socket.on('data', (data) => {
-            logger.log("debug", `Recieved "${data.replace(/(\r\n|\n|\r)/gm, "")}"`);
+            logger.debug(`Recieved "${data.replace(/(\r\n|\n|\r)/gm, "")}"`);
         });
 
         this.m_socket.on("end", () => {
-            logger.log("info", `Disconnected from server localhost:${this.m_port}`);
+            logger.info(`Disconnected from server localhost:${this.m_port}`);
             this.m_online = false;
         });
 
+        this.m_socket.on('error', (err) => {
+            logger.error(`${err}`);
+            if (this.m_online) {
+                this.m_socket.destroy();
+                this.m_online = false;
+            }
+        });
+
         this.m_socket.on("close", () => {
-            logger.log("info", `Socket localhost:${this.m_port} closed`);
+            logger.info(`Socket localhost:${this.m_port} closed`);
             this.m_online = false;
         });
 
         this.m_socket.connect(sockopt, () => {
-            logger.log("info", `Socket connected to localhost:${this.m_port}`);
+            logger.info(`Socket connected to localhost:${this.m_port}`);
             this.m_online = true;
         });
     }
 
     /* Wait for the socket to be connected */
     wait() {
-        logger.log("debug", `Waiting to connect to localhost:${this.m_port}`);
+        logger.debug(`Waiting to connect to localhost:${this.m_port}`);
         var i = 0;
         while (! this.m_online) {
         }
@@ -63,8 +71,12 @@ class LktClient {
 
     /* Close the client */
     close() {
-        logger.log("debug", "Requesting socket shutdown");
-        this.m_socket.destroy();
+        if (this.m_online) {
+            logger.debug("Requesting socket shutdown");
+            this.m_socket.destroy();
+        } else {
+            logger.debug("Socket already closed");
+        }
     }
 }