Remove global scope assumptions
Remove additional global scope asumption
Restructured (and somewhat improved) template creation

This involved moving the creation code from SFTemplateField into a new
class, SFTemplate.

Change-Id: I6e3bc492daca1ffe43f0a5d6af8edab848a4741f
Restored accidentally-reverted earlier change

Change-Id: Iabbe510cafd8bdf0c5c26886006d9ab2adbcea49