Major code refactoring part 6.