Fixed parse errors and undefined variable in foreach loop

Added some commas and semicolons that were missing. Also fixed the for..each loop.