Merge of template patch from Steve Brown