Work on solution

This moves the compilation of the template to the global scope so its only run once. I think this was a suggestion from @whastings back in the day.

Mind taking a look at it and merging @whastings ? :pray: