Added functionality for rerun script, repaired encoding for document.text