Move all gloabls to top of the module

We have too many globals, and they are speard all over the module,
making it hard to see the whole picture. Now they are all in the top of
the module.

Some gloabls were defined using "a = b = ... = None" syntax.  This
syntax is hard to read, so these globals are defined now one global per
line.
Remove bogus global.