Move document generation into execute, and BOM detection