Fixed bug in Document and finished rebuild-script.