Main doc writing