add event listener for main loop