Condense if-logic when checking whether top-level variable exists.

New behavior confirms variable creation prior to other functions being called.

Even if you don't want to use the full pull request as-is, you could reduce some of the code by refactoring the if-statements into simple assignments (i.e. var x = x || {}).