Fix usage of global variables