improved word_count calculation