Totally forgot to ensure access to global variables inside of functions.

This is far from a complete fix and will need to be monitored as time
goes on.