refactoring graefulshutdown