         (widen)
         (setq point-min-line-nr (line-number-at-pos point-min-pos))))
     (unless (window-valid-p live-py-output-window)
-      ;; Recreate output window.
-      (live-py-show-output-window))
+      (live-py-create-output-window))
     (with-selected-window live-py-output-window
       (goto-char 1)
       (forward-line (+ point-min-line-nr window-start-line-nr -2))
       (recenter-top-bottom 0)
       (forward-line (- point-line-nr window-start-line-nr)))))
 
-(defun live-py-check-to-scroll ()
-  "Check if window start or point have to be synchronized."
+(defun live-py-post-command-function ()
+  "Update window start and point of trace buffer if necessary."
   ;; Take extra care to not let this function run into a non-handled error.
   ;; On such an error the debugger will not be entered to not block Emacs
   ;; interactivity when `debug-on-error' is active, so it is easily possible
   ;; to miss the error. And on such an error the function will be removed
-  ;; from `post-command-hook' which can be quite confusing.
-
-  ;; `window-start' is for some reason not up to date after
-  ;; `post-command-hook' in at least these situations:
-  ;; - For a few commands like `narrow-to-region' or `viper-goto-line'.
-  ;; - Repeated `next-line' towards the end of the Python buffer: The trace
-  ;;   buffer suddenly lags one line behind.
-  ;; See also "calculating new window-start/end without redisplay"
-  ;; http://stackoverflow.com/questions/23923371 )
+  ;; from `post-command-hook' which is confusing when not noticed.
   (when (memq this-command '(narrow-to-region next-line viper-goto-line))
+    ;; `window-start' is for some reason not up to date after
+    ;; `post-command-hook' in at least these situations:
+    ;; - For a few commands like `narrow-to-region' or `viper-goto-line'.
+    ;; - `next-line' towards the end of the source buffer: The trace buffer
+    ;;   suddenly lags one line behind.
+    ;; See also "calculating new window-start/end without redisplay"
+    ;; http://stackoverflow.com/questions/23923371
     (redisplay))
   (let ((window-start-pos (window-start))
         (point-line-nr (line-number-at-pos)))

(defvar-local live-py-lighter nil)

(defun live-py-after-change-function (start stop len)
  "Start or restart timer to run `live-py-trace-update'.
START, STOP and LEN are required by `after-change-functions' but unused."
  (ignore start stop len)
  (if live-py-timer

    (setq-local live-py-parent (directory-file-name
                                (file-name-directory live-py-parent))))
  (setq live-py-dir (file-name-as-directory live-py-dir))
  (live-py-update-all)
  (message "Working directory set to %s." live-py-dir))

(defun live-py-set-path()
