Fixes memory leak where event handlers weren't destroyed.