almost done refactoring