Refactoring, fixed event handler not detaching