ok we really need to find a templating language; this is pretty ugly (even something simple like underscore's `template` method would improve readability)