Refactor js character count