Script to generate all documents
Fixed a few memleaks