>Globals are quite ugly, you probably should rather pass this to the various functions.
It's being used in many functions. I think it would better just to mark it static.