Nearly complete refactor.