Improved character counting