Finish (in general) generate_document (still some errors remaining)