Fix bugs caused by last commit

global variables are problematic in main!!