Fix global scoping issues