Moved shutdown logic into λ passed to all exit/quit calls