Refactoring of process_template method