exit gracefully on errors