Bugfix in template to allow string keys
Add templating
Switch to handy memoization function