Refactoring to enable injecting the templator

I think this is pretty good. @tmont?