Fixes #13 nested foreach. Thanks to @danlenharris