Began messy refactoring.