added a loop counter