refactor character counter