changed most functions and vars from global scope to class scope and added an initAll function