Some more cleanups

Includes the first use of Jinja2 for rendering the embedded templates. I haven't tested if all this works, but after looking several times at the changes I didn't found anything obvious.