Allow setting custom functions on templates
Fix tests