add window.document and tweak code style.