Fix issue where document variable is overriden and undefined when run in the browser