This successfully removes references to templates in document, in a very ugly way