refactor iterator usage