Minor fixes

Some error checking and minor template changes