Quite a lot of refactoring.