Switch to a custom way of attaching event listeners that makes it easier to detach them if necessary.