Template system changes

Some more changes to support the template system.