refactor AdvancedWordRepeat

(no functional change, only make it faster)