initial refactor, time for tests now that the spike is over.