removed global variables among other changes