Major code refactoring part 5.