improved timetable logic