To my eye this is a little more inline with my expectations given the test text, but I don't actually have any knowledge of the underlying algorithm yet, so it's just as likely that this change has broken things.
If you feel this doesn't make sense based on your understanding of the algorithm let me know if there is a better approach. I'm happy to make changes.
This looked like a minor change but it has a significant impact on the results returned:
Before:
After:
To my eye this is a little more inline with my expectations given the test text, but I don't actually have any knowledge of the underlying algorithm yet, so it's just as likely that this change has broken things.
If you feel this doesn't make sense based on your understanding of the algorithm let me know if there is a better approach. I'm happy to make changes.