Added comments and tidying, and fixed addRawTemplates to accept basic key value pairs.