major refactoring into modules