Reduce use of global data in core code.  Almost all public APIs are unchanged.
GCC build fixes