nearly finished refactoring