 (defn- add-missing-td-elements-replacing-lesson
   "Adds <td> elements that were removed by the `add-module-lesson` function
    to make way for the lesson."
-  [$parentTd lessonInfo]
-  (let [startTime (:startTime lessonInfo)
-        endTime   (:endTime lessonInfo)]
+  [$parentTd ttLessonInfo]
+  (let [startTime (:startTime ttLessonInfo)
+        endTime   (:endTime ttLessonInfo)]
     (loop [$currentTd $parentTd
            timeIdx    (inc startTime)]
       (if (>= timeIdx endTime)

      (doseq [siblingTdElem (take (- slotsOcc 1) (.nextAll tdHTMLElem))]
        (.remove siblingTdElem))

      ; Returns a map containing information to make it easier to remove the
      ; lesson
      {:day day, :rowNum rowNum, :startTime startTime, :endTime endTime,
       :divElem $divElem})))

(defn- add-module-lesson-group
  "Adds a lesson group of a module to the timetable."
  [moduleCode lessonType lessonLabel bgColorCssClass
   & {:keys [ModulesMap]
      :or   {ModulesMap (aget js/window "ModulesMap")}}]
  (let [moduleName (get-in ModulesMap [moduleCode "name"])
        lessons    (get-in ModulesMap [moduleCode "lessons" lessonType
                                       lessonLabel])]
    (if (and moduleName lessons)
        (let [lessonInfoSeq (doall
                              ; remove lessonIdx
                              (map (fn [[lessonIdx lesson]]
                                     (add-module-lesson moduleCode
                                                        moduleName
                                                        lessonType
                                                        lessonLabel
                                                        lesson
                                                        lessonIdx
                                                        bgColorCssClass))
                                   (map vector
                                        (range 0 (count lessons)) lessons)))]
          ; Update ModulesSelected with the lesson group
          (set! ModulesSelected
                (assoc-in ModulesSelected [moduleCode lessonType]

    (.addClass $divElem bgColorCssClass)
    (.append $divElem (text ($ "<p />") (str moduleCode " " moduleName)))
    (.append $divElem (text ($ "<p />") (str lessonType " [" lessonLabel "]")))
    (.append $divElem (text ($ "<p />") (:venue modulesMapLesson)))
    (width $divElem (str (* half-hour-pixels slotsOcc) "px"))
    (let [dayHTMLElem (nth HTML-Timetable day)
          rowHTMLElem (nth (children dayHTMLElem "tr") rowNum)
