finished initial refactoring