Did some serious refactoring.