outfilename now a global variable