updated with better event listener