The correct way to attach an event handler