Refactoring code from iterator to provider