Remove global variable and ununsed code