added a shutdown callback for catching fatal errors