Fixed templating logic and added test/demo