improved template bulding