Fix crashiness on shutdown (hooray!)