Large refactor.