added error handling for crashes