This looks betters
refactoring template handling among many other things