fix probelm writing to wrong type of filehandle in genstats