improved shutdown behaviour