event listener instead of end function