 
 (defun merlin-error-delete-overlays ()
   "Remove margin error overlays."
-  (mapc #'delete-overlay merlin-pending-errors-overlays)
-  (setq merlin-pending-errors-overlays nil))
+  (remove-overlays nil nil 'merlin-kind 'error))
 
 (defun merlin-error-warning-p (msg)
   "Tell if the message MSG is a warning."

                   (bounds (cons (copy-marker (car bounds))
                                 (copy-marker (cdr bounds)))))
              (acons 'bounds bounds err))))
         (err-overlay
          (lambda (err)
            (let* ((bounds (cdr (assoc 'bounds err)))
                   (overlay (make-overlay (car bounds) (cdr bounds))))
	      (push #'merlin--kill-error-if-edited
		    (overlay-get overlay 'modification-hooks))
              (if (merlin-error-warning-p (cdr (assoc 'message err)))
                  (merlin-put-margin-overlay overlay
                                             merlin-margin-warning-string
                                             'merlin-compilation-warning-face)
                (merlin-put-margin-overlay overlay
                                           merlin-margin-error-string
                                           'merlin-compilation-error-face))
              overlay)))
         (errors   (mapcar err-point errors)))
    (setq merlin-pending-errors errors)
    (when merlin-error-in-margin (setq merlin-pending-errors-overlays
                                       (mapcar err-overlay errors)))))

(defun merlin--error-check (view-errors-p)
  "Check for errors.

  (interactive)
  (setq merlin-pending-errors nil)
  (merlin-error-delete-overlays))

(defun merlin--overlay-p (overlay)
  "Returns non-nil if OVERLAY is managed by merlin."
  (overlay-get overlay 'merlin-kind))

(defun merlin--clear-error-overlay (overlay)
  "Delete an overlay, remove corresponding error from list."
  (let ((err (overlay-get overlay 'merlin-pending-error)))
    (when err (setq merlin-pending-errors
                    (delete err merlin-pending-errors))))
  (delete-overlay overlay))

(defun merlin--kill-error-if-edited (overlay
				     is-after
