implemented character counting mechanism