           {:emptyRows [], :nonEmptyRows []}
           (timetable-enumerate-rows-in-day day)))
 
+(defn- timetable-prune-empty-rows-for-day!
+  "Removes empty rows from a day in `Timetable`, based on the return value of
+   the `timetable-day-get-empty-and-non-empty-rows` function."
+  [day {:keys [emptyRows nonEmptyRows]}]
+  (let [nrNonEmptyRows (count nonEmptyRows)]
+    (set! Timetable
+          (update-in Timetable [day]
+                     (fn [ttDay]
+                       (vec (map (fn [rowIdx]
+                                   (timetable-get-day-row ttDay rowIdx))
+                                 (cond (>= nrNonEmptyRows 2)
+                                       nonEmptyRows
+
+                                       (= nrNonEmptyRows 1)
+                                       [(first nonEmptyRows)
+                                        (first emptyRows)]
+
+                                       :else
+                                       (take 2 emptyRows)))))))))
+
 (defn- create-lesson-div
   "Creates a <div> element for a new lesson using jQuery"
   [& {:keys [moduleCode moduleName lessonType lessonGroup venue slotsOcc

  [day]
  (nth Timetable day))

(defn- timetable-get-day-row
  "Retrieves a row for a given day in `Timetable`."
  [day rowNum]
  (nth (timetable-get-day day) rowNum))

; Returns the total number of rows for a given day in the Timetable.
(defmulti timetable-day-get-nr-rows number? :default false)

                            (.stringify js/JSON (clj->js emptyRows))
                            ", nonEmptyRows = "
                            (.stringify js/JSON (clj->js nonEmptyRows))))

      (timetable-prune-empty-rows-for-day! day
                                           {:emptyRows    emptyRows,
                                            :nonEmptyRows nonEmptyRows})
      ; shift <th> element to the new 0th row
      (if (and (zero? (first emptyRows)) (> nrNonEmptyRows 0))
          (prepend (nth (children $day "tr") (first nonEmptyRows)) $thElem))
