various changes to make template system work better