Ensured correct shutdown behaviour