better error handling from R