full rewrite using recursive templating