Massive refactor.