Crazy big refactor.