fixed dead loop caused by `document.write`