       (cons (string  c) (progn (delete-char 1) (gobble-line)))
       )))
 
-(defun explodec (string)
-  (cond ((equal string "") nil)
-	((equal "\n" (substring string 0 1)) nil)
-	((cons (substring string 0 1) (explodec (substring string 1))))
-	))
-
-(defun remove-newline (list)
-  (if (equal "\n" (car list))
-      nil
-    (cons (car list) (remove-newline (cdr list)))))
-
-;;; convert a list of chords and a list of lyrics
 (defun inline-chords (chords lyrics)
-  (cond ((null chords) (concat-list lyrics))
-	((null lyrics) "")
+  "This function takes a line of chords and a line of lyrics, passed as lists of
+single-character strings, and converts them to a single line with chords inlined
+in brackets."
+  (cond ((null chords) lyrics)
 	((equal " " (car chords))
-	 ;; things are simple if the chords line starts with space
-	 (concat (car lyrics) (inline-chords (cdr chords) (cdr lyrics))))
-	 ;; otherwise, put out a left bracket and start converting the chord
-	 ;; the third argument to in-chord accumulates characters from lyrics
-	((concat "[" (convert-chord chords lyrics "")))
+	 (if (null lyrics)
+	     (cons " " (inline-chords (cdr chords) nil))
+	   (cons (car lyrics) (inline-chords (cdr chords) (cdr lyrics)))))
+	((cons "[" (convert-chord chords lyrics "")))
 	))
 
 (defun convert-chord (chords lyrics lyrics-under-chord)
-  ;;"convert a chord at the front of lyrics, and follow it with the remaining lyrics"
-  (cond ((null chords) (concat "]" lyrics-under-chord (concat-list lyrics)))
+  "Convert a chord at the front of lyrics, and follow it with the remaining lyrics.
+The lyrics under the chord are accumulated in a string."
+  (cond ((null chords) (cons "]" (if (equal "" lyrics-under-chord)
+				     lyrics
+				   (cons lyrics-under-chord lyrics))))
 	((equal " " (car chords))
-	 ;; space in chords means we're done with the one we were working on
-	 (concat "]"
-		 lyrics-under-chord
-		 (inline-chords chords lyrics)))
-	;; otherwise, add a converted chord character to the output and handle the tail.
-	((concat (convert-chord-char (car chords) (cdr chords))
-		 (convert-chord (cdr chords)
-				(cdr lyrics)
-				(concat lyrics-under-chord (car lyrics)))))
+	 (cons "]" (if (equal "" lyrics-under-chord)
+		       (inline-chords chords lyrics)
+		     (cons lyrics-under-chord (inline-chords chords lyrics)))))
+	((null lyrics)
+	 (cons (convert-chord-char (car chords) (cdr chords))
+	       (convert-chord (cdr chords) nil lyrics-under-chord)))
+	((cons (convert-chord-char (car chords) (cdr chords))
+	       (convert-chord (cdr chords)
+			      (cdr lyrics)
+			      (concat lyrics-under-chord (car lyrics)))))
 	))
-	       
+
+		 
 ;;; Convert a single character in a chord.
 ;;;    # -> \sharp
 ;;;    b -> \flat

;;; Convert lyrics from "chords above text" to chords inline in brackets.
;;

(provide 'flktex-utils)
(setq max-lisp-eval-depth 6000)

    (beginning-of-line)
    (if (looking-at "^[:space:]*$")
	(progn (gobble-line) (insert "\\\\"))
      ;; this would be simpler in Haskell, where a string is just a list of characters.
      ;; as it is, we use lists to avoid creating unnecessary intermediate strings.
      (mapc 'insert (inline-chords (gobble-line) (gobble-line))))
    (insert "\n"))

(defun gobble-line ()
