Refactored the code that compiles the templates.