replace open-coded for_each_child loop