Better shutdown logic/hooks.