The problem has been solved mistake in initial value of counter
giving a universal value of change
Calculation is speed up by using modulus