Adding a loop counter for allocation