Thanks, I had already fixed this, but apparently not in the master branch yet.
The correct fix is to use trx->bts, rather than bts. Skipping/removing patch_nm_tables() can cause erroneous data from the templates to leak into the live system without reflecting the configuration file.
I'll fix it in master right now.