Improved document generation