Refactoring of process_template; add get_template.