Replaced range-based for loop with BOOST_FOREACH to support old compilers