Fixed some bugs where eventsToPeriods would break due to i being out of
range