Simplify foreach body
Remove recursion
Make the code more explicit, simplify foreach body