fix various shutdown issues