Made export filenames safer and better error messages for references