implemented word count

accuracy not guaranteed but it seems to work all right