refactor shutdown and crash to new pattern

graceful shutdown logic improved