structural refactoring with all tests still working. will clean up later.