Add fields to templates; refactor