a lot of refactoring and reorganization