Add query logging
More sensible template invoker