Implement DOM-free event dispatching.

Small fixes and cleanup.