Many refactorings throughout.