Total refactoring of code