Added word count and fixed a IO bug.