refactoring nearly finished