Extract method for token generation.