 (defn- add-module-lesson
   "Adds a single lesson of a module (obtained from the `ModulesMap` global) to
    the timetable, and returns its jQuery div element."
-  [moduleCode moduleName lessonType lessonLabel lesson bgColorCssClass]
+  [moduleCode moduleName lessonType lessonLabel lesson lessonIdx
+   bgColorCssClass]
   (let [rowNum      (find-free-row-for-lesson lesson)
         day         (:day lesson)
         startTime   (:startTime lesson)

                                       lessonLabel])]
    (if (and moduleName lessons)
        (let [lessonInfoSeq (doall
                              (map (fn [lesson]
                                     (add-module-lesson moduleCode
                                                        moduleName
                                                        lessonType
                                                        lessonLabel
                                                        lesson
                                                        bgColorCssClass))
                                   lessons))]
          ; Update ModulesSelected with the lesson group
          (set! ModulesSelected
                (assoc-in ModulesSelected [moduleCode lessonType]

    ; Create new row if necessary
    (if (= rowNum (get-nr-rows-in-timetable-day day))
        (add-new-row-to-timetable-day day))

    ; Update in-memory representation of timetable
    (timetable-mark-lesson-slots-occupied
      day rowNum startTime endTime
      {:moduleCode moduleCode, :lessonType lessonType, :lessonGroup lessonLabel,
       :index lessonIdx})

    ; add background color css class
    (.addClass divElem bgColorCssClass)
