first pass of new template code