    :noquery t))
 
 (defun emdocs-broadcast-message (msg)
+  (message msg)
   (loop for client in *emdocs-clients*
         do (process-send-string client msg)))
 
-(defun emdocs-emit-keypress-json (type point content)
+(defun emdocs-emit-keypress-json (buffer type point content)
   (emdocs-broadcast-message
    (json-encode
-    `(:buffer ,(buffer-name)
+    `(:buffer ,(if (bufferp buffer)
+                   (buffer-name buffer)
+                 buffer)
       :edit_type ,type
       :point ,point
       :content ,content))))
 
-(defun emdocs-after-change-function (beg end prev-length)
-  (unless emdocs-is-network-insert
-    (cond ((= prev-length 0)
-           (emdocs-emit-keypress-json
-            "insert" beg (buffer-substring beg end)))
-          ((= beg end)
-           (emdocs-emit-keypress-json
-            "delete" beg prev-length)))))
+(defun emdocs-after-change-function (buffer beg end prev-length)
+  (with-current-buffer (buffer-name buffer)
+    (if (boundp 'emdocs-is-network-insert)
+        (unless emdocs-is-network-insert
+          (cond ((= prev-length 0)
+                 (emdocs-emit-keypress-json
+                  buffer "insert" beg (buffer-substring beg end)))
+                ((= beg end)
+                 (emdocs-emit-keypress-json
+                  buffer "delete" beg prev-length))))
+      (message "WHAT"))))
+
+(defvar-local emdocs-client-list nil
+  "docstring")
+
+(defvar-local emdocs-ip-addr nil
+  "docstring")
+
+(defvar-local emdocs-is-network-insert nil
+  "docstring")
 
 (defun emdocs-attach-sockets-to-buffer (buffer ip)
   "docstring"


(defun emdocs-get-client-process-buffer (buffer)
  "docstring"
  (concat "*emdocs-client-log:" (buffer-name buffer) "*"))

(defun emdocs-get-server-process-name ()
  "docstring"

                       (setq emdocs-mode nil)
                       (emdocs-disconnect))
              (with-current-buffer buffer
                (setq emdocs-is-network-insert nil)
                (setq-local after-change-functions
                            (cons
                             (lambda (beg end prev-length)
                               (emdocs-after-change-function
                                buffer beg end prev-length))
                             after-change-functions))))))
      (message "Not connected to internet: exiting.")
      (setq emdocs-mode nil)
      (emdocs-disconnect))))

(defun emdocs-connect ()
  "docstring"
  (setq emdocs-ip-addr (read-from-minibuffer "ip: "))
  ;; check for private ips
  (if (or (string-match "^192\\.168\\.[0-9]+\\.[0-9]+$" emdocs-ip-addr)
