Complete first pass refactoring