Removed some global variables, other minor changes