Fixed a problem where internal events were not detached when stopping the application.