Big bunch of refactorings.