Move shutdown functionality to a public method.