Major code refactoring.