Added template processing code