added some code to extract templates from log_bags