nearly done refactoring