fix logic for token count