Refactor loops.