This will allow using this code from other places and not only when executing user-defined event handlers. No changes in this commit yet.