Added functions to count the events in each time period