Implements final refactoring of the code.