probably you need to define the total counter as a global variable.
to be sure please post your code.