Fixes event listener infinite loop