do we need a transaction inside the foreach loop to make it atomic?