refinalized and automated template construction