Write the documents
Fix infinite loop bug