Refactoring of counter, still needs proper overflow