Modified code to extract past and upcoming events