Getting rid of global variable