Refactored iterator with test