Fixes some bugs in event listeners