Added the terminate all function and added it to the place where it can ...

...happen.