 (defn- create-day-repr
   "Creates in-memory representation of a single day in the timetable.
 
-   Each day is a vector of rows, and there is a minimum of 2 rows in each day.
+   Each day is a vector of rows, and there is a minimum of
+   `TIMETABLE-MIN-ROWS-FOR-DAY` rows in each day.
    Multiple rows are needed when there are lessons with overlapping start and
    end time."
   []
-  [(create-empty-timetable-row) (create-empty-timetable-row)])
+  (loop [ttDay           []
+         nrRowsRemaining TIMETABLE-MIN-ROWS-FOR-DAY]
+    (if (zero? nrRowsRemaining)
+        ttDay
+        (recur (conj ttDay (create-empty-timetable-row))
+               (dec nrRowsRemaining)))))
 
 (defn timetable-create!
   "Initializes the in-memory representation of the timetable.

        $thElem        (.find $day "tr > th")
        nrNonEmptyRows (count nonEmptyRows)

        rowsToRemove
        (cond (>= nrNonEmptyRows 2) emptyRows
              (=  nrNonEmptyRows 1) (rest emptyRows)
              :else                 (drop 2 emptyRows))]
    ; shift <th> element to the new 0th row
    (if (and (zero? (first emptyRows)) (> nrNonEmptyRows 0))
        (prepend (nth (children $day "tr") (first nonEmptyRows)) $thElem))

    ; remove empty <tr> elements
    (doseq [[idx rowIdx] (map vector
                              (range (count rowsToRemove))
                              rowsToRemove)]
      (.remove (nth (children $day "tr") (- rowIdx idx))))

    (if (and (= nrNonEmptyRows 1)
             (zero? (first emptyRows)))
        (let [$trArray (children $day "tr")]
          (.log js/console "Am gonna swap this shit man")
          (.log js/console (str "$trArray = " $trArray ", 0th = " (nth $trArray 0) ", 1st = " (nth $trArray 1)))
          (before (nth $trArray 0) (nth $trArray 1))))

    ; adjust rowspan of <th>
    (attr $thElem "rowspan" (max nrNonEmptyRows 2))))

(defn- create-lesson-div
  "Creates a <div> element for a new lesson using jQuery"

  (doseq [day (range 5)]
    (let [nrRows   (timetable-day-get-nr-rows day)
          $dayElem (nth HTML-Timetable day)]
      ; Remove rows >= TIMETABLE-MIN-ROWS-FOR-DAY
      (doseq [rowIdx (reverse (range TIMETABLE-MIN-ROWS-FOR-DAY nrRows))]
        (.remove (nth (children $dayElem "tr") rowIdx)))
      ; Remove all <td>
      (.remove (.find $dayElem "td"))
      ; Add clean <td>
      (doseq [rowIdx (range TIMETABLE-MIN-ROWS-FOR-DAY)]
        (.append (nth (children $dayElem "tr") rowIdx)
                 ($ Timetable-Row-TD-HTML-String)))
      (attr (.find $dayElem "tr > th") "rowspan" TIMETABLE-MIN-ROWS-FOR-DAY))))

(defn- add-module-lesson!
  "Adds a single lesson of a module the timetable.
