Fix control flow issues.
Introduce FOR_xxx macros for looping through objects.
Use FOR_xxx macros in container.c.