Register event listener correctly