Refactor RequireJS load
Refactor handleEvent function to dispatch based on event type.