Hi, and welcome to the Ranch!
When posting code, please
UseCodeTags(←click) so that it will be readable. I added them for you this time.
As for your specific problem, it sounds like you're not resetting some counter to zero for each word.
Something like that.
I don't feel like poring over your code right now to try to find it, but hopefully now you have some idea what you're looking for.
And if you're having a hard time figuring out which set of braces is enclosing what, then you've got too much code and/or too much nesting in one method. Move some of the steps or inner nesting levels to their own methods.
And finally, if you can't figure out what's going on in your code, add a bunch of print statements telling you where you are and what various significant values are. You can compare that output to what you expect to happen, and where reality differs from expectation, that's where you start looking for your bug.