Change iterative code to match batch code