Refactoring iteration on list