another round of massive refactoring