More work on samples, coverage for raw templates, tidyup of code