Shutdown fixes from Lars.