This fixes a couple problems when exiting due to signal: