Bring the global variables more into their context

I'm actually being a bit picky here. If you feel the same, just close the PR :smile: