[WIP]Refactor some occurences of "two-iteration loop" anti-pattern

Influenced by #572