Fixes; #2731 Mostly fixed template system