Refactore source window/document usage
(part 8 for #1)
Correctly handle closed windows:
new versions may throw "can't access dead object" error