Moved foreach into iterator