Replace deprecated "with_items" with loops