Moved static variables

Put static variables inside functions instead of making them global