refactoring graceful shutdown - WIP