refactoring nearly complete