Added inner method counter() and tests.