Added template based on "type" attribute and a few other things.