fix the foreach script