 (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 lessonIdx
-   bgColorCssClass]
-  (let [rowNum      (find-free-row-for-lesson lesson)
-        day         (:day lesson)
-        startTime   (:startTime lesson)
-        endTime     (:endTime lesson)
-        slotsOcc    (- endTime startTime)
-        divElem     ($ "<div />" (js-obj "class" "lesson"))
-        [hourClass minuteClass] (get-css-hour-minute-classes-for-time
-                                  startTime)]
+  [moduleCode moduleName lessonType lessonLabel lesson bgColorCssClass]
+  (let [rowNum    (find-free-row-for-lesson lesson)
+        day       (:day lesson)
+        startTime (:startTime lesson)
+        endTime   (:endTime lesson)
+        slotsOcc  (- endTime startTime)
+        $divElem  ($ "<div />" (js-obj "class" "lesson"))
+
+        [hourClass minuteClass]
+        (get-css-hour-minute-classes-for-time startTime)]
     ; 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})
+    (timetable-add-lesson day rowNum
+                          {:moduleCode moduleCode,
+                           :lessonType lessonType,
+                           :lessonGroup lessonLabel,
+                           :startTime startTime,
+                           :endTime endTime}
+                          $divElem)
 
     ; add background color css class
-    (.addClass divElem bgColorCssClass)
-    (.append divElem (text ($ "<p />") (str moduleCode " " moduleName)))
-    (.append divElem (text ($ "<p />") (str lessonType " [" lessonLabel "]")))
-    (.append divElem (text ($ "<p />") (:venue lesson)))
-    (width divElem (str (* half-hour-pixels slotsOcc) "px"))
+    (.addClass $divElem bgColorCssClass)
+    (.append $divElem (text ($ "<p />") (str moduleCode " " moduleName)))
+    (.append $divElem (text ($ "<p />") (str lessonType " [" lessonLabel "]")))
+    (.append $divElem (text ($ "<p />") (:venue lesson)))
+    (width $divElem (str (* half-hour-pixels slotsOcc) "px"))
     (let [dayHTMLElem (nth HTML-Timetable day)
           rowHTMLElem (nth (children dayHTMLElem "tr") rowNum)
           tdHTMLElem  (nth (children
                              rowHTMLElem
                              (str "td" "." hourClass "." minuteClass))
                            0)]
-      (.append tdHTMLElem divElem)
+      (.append tdHTMLElem $divElem)
       ; Increase colspan and delete the <td> after it that occupy the timeslot
       ; of the lesson
       (attr tdHTMLElem "colspan" slotsOcc)

            [clojure.string]
            [cljs-nusmods.select2 :as select2]
            [cljs-nusmods.time    :as time-helper]))

(def ^{:doc     "Width in pixels of a half hour timeslot"
       :private true

        thElem (.find (nth HTML-Timetable day) "tr > th")]
    (attr thElem "rowspan" nrRows)))

(defn- timetable-add-lesson
  "Adds a lesson to the `Timetable` global, effectively 'marking' the
   time interval for that lesson as being occupied."
  [day rowNum ttLessonInfo $lessonDiv]
  (set! Timetable
        (update-in Timetable
                   [day rowNum]
                   (fn [ttRow]
                     (assoc ttRow ttLessonInfo $lessonDiv)))))

; TODO - update this function
; It was formerly called timetable-mark-lesson-slots-free
(defn- timetable-remove-lesson
  "Removes a lesson from the `Timetable` global, effectively 'marking' the
   time interval occupied by that lesson as free."
  [day row ttLessonInfo]
  (let [day         (:day lessonInfo)
        row         (:rowNum lessonInfo)
        startTime   (:startTime lessonInfo)
