rewrite to avoid event listener lost