yet another deep refactoring -- work in progress