   (let ((recon-window (get-buffer-window (get-buffer ledger-recon-buffer-name))))
     (when recon-window
       (fit-window-to-buffer recon-window)
-      (with-current-buffer buf
+      (with-current-buffer ledger-buf
         (add-hook 'kill-buffer-hook 'ledger-reconcile-quit nil t)
-        (if (get-buffer-window buf)
-            (select-window (get-buffer-window buf)))
+        (if (get-buffer-window ledger-buf)
+            (select-window (get-buffer-window ledger-buf)))
         (goto-char (point-max))
         (recenter -1))
       (select-window recon-window)

          (when (not (eq buf rbuf))
            ;; called from some other ledger-mode buffer
            (ledger-reconcile-quit-cleanup)
            (set 'ledger-buf buf)) ;; should already be buffer-local

          (unless (get-buffer-window rbuf)
            (ledger-reconcile-open-windows buf rbuf)))

        (insert "Ledger has reported a problem.  Check *Ledger Error* buffer.")))
    (goto-char (point-min))
    (set-buffer-modified-p nil)
    (setq buffer-read-only t)

    (ledger-reconcile-ensure-xacts-visible)
    (length xacts)))
