rewrite document.write