Cleanups/globals exports

Unexporting local variables, constification of local variables, getting rid of global variables.