Use the foreach syntax.
Log: Avoid some infinite recursion.
Some minor code cleanup.