replace some traversal with BOOST_FOREACH