Refactored to use document and document.scene instead of scene global.
Remove use of document global.