Lots of refactoring.