Adds basic refactoring of the main code.