Create initHandler function to set event handlers