replaces document.foo references by doc.foo
borrows head tag selection from restyle.js
shrinked file size