Refactoring (mostly) complete