Cleanups
Cleanup: Move constant inside function

It was not used in any other place, so this makes clearer that can be
removed with no side effects.
Simplified event binding/handling
Simplified some code
Don't poison the global scope