move to top level beforeach