major refactoring for more modularity.