Relocated certain variables to global space, rewritten variable setting mechanic.