Major code refactoring part 3.