Fixes a bug introduced by the globals change

And adds new tests to exercise some code that wasn't being hit before.