massive refactor.