added shutdown handler to catch fatal errors