Refactoring of all of the code