add safety shutdown handler