Saving memory issues, do not load classes if we don't need it
Reformat code, adding comments and moving db tables inside functions in events.lib.inc.php