updated global var names and fixed mode setting