Re-factoring query_templates.