a very large refactor/reorganization