Replace new Function generated template callback with a closure