Major refactoring job to reduce redundancies.