Make shutdown safer