Make nearly all setup code non-static and non-global

Change-Id: Ia477610f3c35b6edbab983af32c88eb8697fc3e7