Trying new template generation algorithm