Make all top level variables globals when they're moved

Also fixed bug introduced by globals