added missing braces {} on foreach and if
Merge pull request #5550