The previous loop was too convoluted and not easy to follow.
Had a bug of not adding the last lecture of a day because the statement of adding the previous course at the end of the day was unreachable.
Put that code outside the loop of the cells (hours) and instead at the end of each iteration of the row loop (days).
It works with my timetable: Empty work days and variable length classes, but please verify once with other timetables.
sorry for the last two pr they had extra files I made for debugging :p
It works with my timetable: Empty work days and variable length classes, but please verify once with other timetables. sorry for the last two pr they had extra files I made for debugging :p