updated to use foreachlimit