Wrap the whole thing in a function so as not to pollute the global namespace.
Merge branch 'fix-events'