Done some major refactoring.