lots of refactoring and clean up throughout all