Convert forEach to for loop to avoid closure.
Support objects of entities.