Iterate over all units in chunks

Signed-off-by: Michal Čihař <michal@cihar.com>
Move iteration to shared code

Signed-off-by: Michal Čihař <michal@cihar.com>