Done a bit of refactoring.