       (add-hook (car hook) (cdr hook) nil 'local)))
    (t
     (dolist (hook ycmd-hooks-alist)
-      (remove-hook (car hook) (cdr hook) 'local)))))
+      (remove-hook (car hook) (cdr hook) 'local))
+    (ycmd--teardown))))
 
 ;;;###autoload
 (defun ycmd-setup ()

    (setq ycmd--on-focus-timer
          (run-at-time 1.0 nil #'ycmd--on-unparsed-buffer-focus))))


(defconst ycmd-hooks-alist
  '((after-save-hook                  . ycmd--on-save)

      (when (ycmd-running?)
        (delete-process ycmd--server-process)))

  (ycmd--kill-timer ycmd--keepalive-timer)
  (ycmd--global-teardown))

(defun ycmd-running? ()
  "Tells you if a ycmd server is already running."
