 ; Data type Definitions
 ; =====================
 ;
-; TimetableLessonInfo (short form: ttLessonInfo)
-; ----------------------------------------------
-; Describes a lesson in the `Timetable` global.
-; Each instance is a map in the following format:
+; TimetableLessonInfo (abbrev: ttLessonInfo)
+; ------------------------------------------
+; Describes a lesson in the `Timetable` global; this is the key used for each
+; row in a day of the `Timetable`.
+;
+; Each instance of `TimetableLessonInfo` is a map in the following format:
 ;
 ;   {
 ;     :moduleCode  -> module code string of this lesson

                   (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)
        endTime     (:endTime lessonInfo)
        ttRow       (get-in Timetable [day row])
        occupiedVec (reduce (fn [occupiedVec timeIdx]
                              (assoc occupiedVec timeIdx nil))
                            (:occupied ttRow)
                            (range startTime endTime))]
    (set! Timetable
          (update-in
            Timetable [day row]
            (fn [ttRow]
              {:nrLessons (dec (:nrLessons ttRow))
               :occupied  occupiedVec})))))

(defn- find-free-row-for-lesson
  "Returns the 0-indexed row which can accomodate the given lesson (timeslots

  "Removes a lesson group for a module from the HTML timetable.
   This does NOT remove any empty rows / perform module shifting.

   Returns a sequence of `ttLessonInfo` objects which contain
   additional `:day` and `:rowNum` keys."
  [moduleCode lessonType]
  (let [lessonGroupDetails (get-in ModulesSelected [moduleCode lessonType])
        lessonGroup        (:label lessonGroupDetails)
        lessonInfoSeq      (:info lessonGroupDetails)]
    (map (fn [modSelLessonInfo]
           (let [day          (:day modSelLessonInfo)
                 rowNum       (:rowNum modSelLessonInfo)
                 startTime    (:startTime modSelLessonInfo)
                 endTime      (:endTime modSelLessonInfo)
                 ttRow        (get-in Timetable [day rowNum])
                 ttLessonInfo {:moduleCode moduleCode, :lessonType lessonType,
                               :lessonGroup lessonGroup, :startTime startTime,
                               :endTime endTime}
                 $lessonDiv   (get ttRow ttLessonInfo)
                 $parentTd    (parent $lessonDiv)]
             ; Remove the `colspan` attribute of the parent <td> so it has
             ; colspan=1
             (remove-attr $parentTd "colspan")
             ; Remove the HTML div elem
             (.remove $lessonDiv)
             ; Add the missing <td> elements
             (add-missing-td-elements-replacing-lesson $parentTd ttLessonInfo)
             (assoc ttLessonInfo :day day, :rowNum rowNum)))
         lessonInfoSeq)))

(defn remove-module
