Fix TEvent handling so it doesn't crash anymore.
Fix memory leaks in the way pcre is used.