Main refactor done, all tests pass