fixed file IO in stats.py