changed and got rid of global variables