Reduce use of globals

Or reduce the scope where they are available.

Change-Id: Idce74bda8f64cc6be62b58b2624629408ca18d4b
Merge "Reduce use of globals"