added missing braces {} on foreach and if