Template code and other fixes.