Convert some token id functions to templates