finally removed global variable, simplified some stuff