Render cleanup

Please review the changes, some of them might be breaking (eg. the `domhandler` never emits a `template` node, but there might be other uses I don't know about).