Iteration logic improved