fixed some global variable stuff
merged