Templatematch improvements

This is the patch for mine and Aiman's reworking of the template match process, parameters, config file, etc.