new support for processing of template structure and major bug fixes