Replaces NIC substituions with template

- adds tests for _gen_xml, and prepare_nic_xml
- some misc bugs from my earlier changes