Finally worked out templating problems