parse_events function