Fixed issues with empty document
Fixed issue with infinite loop on patching

This issue occurs if new section must be inserted after comment