fix bugs foreach