Cleaned up shutdown process.