fixed broken loop counter