Changed all references to global variable into references to a struct param element (very hacky though).