Tried to fix some errors with BOOST_FOREACH

I capped each call to BOOST_FOREACH with {} to be sure the scope was
maintained properly.