Fix bug with shutdown