template.json is no longer in the data directory
Simplify term extraction code

This also removes duplicate keywords from the term list.
Remove globals and pass them explicitly to the handlers