generalized templating system. must test