fixed bug with closing empty outfile